kobus_2000

kobus_2000

  • NA
  • 14
  • 0

Inserting data into Excel sheet using sql

Jul 18 2005 5:59 AM
Hi

 

I am using the Microsoft.Jet.OLEDB to connect to an Excel workbook

 

I can use the following sql to insert data into the Excel sheet (I hope my syntax is correct. I do not have the compiler with me):

 

String sql = "Insert INTO [Sheet1$] (Lastname, Firstname1) Values ('XXX', 'YYY')";
OleDbCommand cmdExcel = new OleDbCommand(sql,  conn);
OleDbDataReader drExcel = cmdExcel.ExecuteReader();

 

The problem that I have, is that for that INSERT to work those column headers (eg Lastname, Firstname1) need to exist in the workbook. I want to create a new workbook using code and insert data without having column names to insert the data under. How would I change the INSERT sql to specify in which column to insert data in (eg in A, B, etc).?

 

Thanks.
Kobus

Answers (1)