title: How to import specific cells of an Excel file into datagridview using c#
body: <p>I want to import specific cells of an Excel file to specific cells of a datagridview.</p>
  
  <p>I followed many tutorials here that import Excel tables, but as I want only specific cells in specific locations of the datagridview, I adapted the code.</p>
  
  <p>Instead of: <code>DataGridView1.DataSource = dt;</code> I did: <code>dataGridView1.Rows[0].Cells[0].Value = dt;</code> but it doesn’t work.</p>
  
  <p>Can anyboby help me please?</p>
  
  <p>Thank you</p>
  
  <p>Here is the code:</p>
  
  <pre><code>string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + @";Extended Properties=""Excel 12.0 Macro;HDR=YES;ImportMixedTypes=Text;TypeGuessRows=0""";
  
          OleDbConnection con = new OleDbConnection(constr);
  
          //specific cell 1 - product "code"
          OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [ARTIGOS$A" + textBox3.Text + ":A" + textBox3.Text + "]", con);
          //specific cell 2 - product "description"
          OleDbDataAdapter sdb = new OleDbDataAdapter("select * From [ARTIGOS$B" + textBox3.Text + ":B" + textBox3.Text + "]", con);
          //specific cell 3 - product "price"
          OleDbDataAdapter sdc = new OleDbDataAdapter("Select * From [ARTIGOS$I" + textBox3.Text + ":I" + textBox3.Text + "]", con);
  
          DataTable dt = new DataTable();
          DataTable dt2 = new DataTable();
          DataTable dt3 = new DataTable();
  
          sda.Fill(dt);
          sdb.Fill(dt2);
          sdc.Fill(dt3);
  
          dataGridView1.Rows.Add();
          dataGridView1.Rows[0].Cells[0].Value = dt;
          dataGridView1.Rows[0].Cells[1].Value = dt2;
          dataGridView1.Rows.Add();
          dataGridView1.Rows[0].Cells[2].Value = textBox2.Text;
          dataGridView1.Rows[0].Cells[3].Value = dt3;
  </code></pre>