473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Can't get OleDbCommandBuilder.GetInsertCommand() working

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[i].ToString();

Pointers welcome - its quite annoying.
Probably something dead simple i'm missing but i just copied it line
by line.
Sep 29 '08 #1
0 1918

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Torben Madsen | last post by:
Hello, I'm trying to save the changes back to the database, but it doesn't work -could anybody help me? I'm using a DataSet and the wierd thing is that I can save the changes in the memory but...
2
by: ¹ùÑÇ·æ | last post by:
first of all ,i will thank you for reading this . :-) i am writing a programming to access SQL-SERVER. i use some codes as follows in order to update data changed in datagrid1. but i found that...
1
by: Locke | last post by:
I know I'm doing something wrong, and it's something simple but I can't figure it out. I'm new at this and it's only a little more than a hobby so please bear with me. I'm writing a VB shell...
0
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If...
2
by: Josema | last post by:
Hi to all, Im getting an error that in theory is simple but i dont understand... This is the line when i get the error, and the oledbcmd is well created, with the connection opened, the...
4
by: Arne Beruldsen | last post by:
I just can't seem to get the datagridview to update. I'm using 2005 vb.net Here's my code for loading the grid (works fine) and my attempt at updating via a save button... Private SxAdapter...
3
by: =?Utf-8?B?TXJrIEJsYWNrYWxs?= | last post by:
Hi all, This is my first attempt to update an access database in VB.Net 2005. It goes broadly as follows (I have condensed it): Dim MyConnection As New Data.OleDb.OleDbConnection...
2
by: triffid | last post by:
Hi there, I'm trying to update my database via an UPDATE from OleDbCommandBuilder. This is the second time I've tried, and I'm still not having any luck. I've almost certainly missed something...
0
by: =?Utf-8?B?QTdtYWQ=?= | last post by:
Hi all, I'm using OleDbCommandBuilder to build commands for an OleDbDataAdapter automatically The problem is when using OleDbDataAdapter to retrieve data from a "View" in a SQL Express...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.