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}]";
excelDataAdapte r = new OleDbDataAdapte r(string.Format (_excelSelect,
dt.TableName), excelFile);
excelCommandBui lder = new OleDbCommandBui lder(excelDataA dapter);
excelCommandBui lder.QuotePrefi x = "[";
excelCommandBui lder.QuoteSuffi x = "]";
excelDataAdapte r.InsertCommand =
excelCommandBui lder.GetInsertC ommand();
excelDataAdapte r.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[i].ToString();
Pointers welcome - its quite annoying.
Probably something dead simple i'm missing but i just copied it line
by line.
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}]";
excelDataAdapte r = new OleDbDataAdapte r(string.Format (_excelSelect,
dt.TableName), excelFile);
excelCommandBui lder = new OleDbCommandBui lder(excelDataA dapter);
excelCommandBui lder.QuotePrefi x = "[";
excelCommandBui lder.QuoteSuffi x = "]";
excelDataAdapte r.InsertCommand =
excelCommandBui lder.GetInsertC ommand();
excelDataAdapte r.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[i].ToString();
Pointers welcome - its quite annoying.
Probably something dead simple i'm missing but i just copied it line
by line.