Can't get OleDbCommandBuilder.GetInsertCommand() working

J

JB

Code is taken straight from a book but i can't get it working right.
Its generating an insert statement for inserting data into an excel
file.


//foreach (DataTable dt in ds.Tables)
//private const string _excelSelect = "select * from [{0}]";

excelDataAdapter = new OleDbDataAdapter(string.Format(_excelSelect,
dt.TableName), excelFile);
excelCommandBuilder = new OleDbCommandBuilder(excelDataAdapter);
excelCommandBuilder.QuotePrefix = "[";
excelCommandBuilder.QuoteSuffix = "]";
excelDataAdapter.InsertCommand =
excelCommandBuilder.GetInsertCommand();
excelDataAdapter.Update(ds, dt.TableName);

notes:
ds is a dataset
dt is from 'a DataTable inside ds.Tables

-
The problem is the insert command generated doesnt contain any values
- instead it just has "?".
It is perfect in formatting but it ends up like:
INSERT INTO tablename [Column1],[Column2],[Column3] VALUES(?,?,?)

Other than that its fine..
It inserts into the file the column headings but with no data.

Any ideas?

The dataSet and datatable contains data - as I can see if I debug and
traverse it row by row like:

foreach (DataRow dataRow in dt.Rows)
string x = dataRow.ToString();

Pointers welcome - its quite annoying.
Probably something dead simple i'm missing but i just copied it line
by line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top