0

I want to insert data to excel sheet using Excel query. The problem is, the sheet I want to insert data in contains some data above header row. Excel detects first data row as its header row. So when I insert data like this:

OleDbCommand cmd = new OleDbCommand("Insert into [Sheet1$] (id, name, lastname) values ('1', 'jim', 'carry')");

This query is not able to find columns because first row contains some other information. Can anyone please help me how can I insert rows after my header row specifically.

  • Take a look at this question, it might help you: http://stackoverflow.com/questions/3174904/creating-an-excel-workbook-via-oledb-without-headers – NDraskovic Sep 03 '14 at 06:56
  • You can temporarily remove the 1st row and then add it back? Or try a combination of `[Sheet1$A2]` although I am not sure this works... –  Sep 03 '14 at 11:12
  • Its not just one row. I can have random data with any number of rows in header. – Mufaddal Shafqat Sep 03 '14 at 11:28
  • Well, find the last row and concatenate it into `Sheet$A:` + `int.Parse(lastRow)` or something similar –  Sep 03 '14 at 11:35

0 Answers0