473,395 Members | 1,885 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,395 software developers and data experts.

Problems with OleDbCommandBuilder

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 obvious,
but having searched for quite a while, I don't know what it is(!)

The code is here (intentionally showing source rather than having
server run page):-
http://home.freeuk.com/misacham/temp...ER_UPDATE.aspx
and this is the Access DB I'm using:-
http://home.freeuk.com/misacham/temp/writable.mdb

(I considered pasting the whole longwinded thing here, but wasn't sure
that this would be a good idea.)

Here's what happens when I try to run it on my local Windows XP
machine ("Syntax error in UPDATE statement", apparently because UPDATE
statement is null):-
http://home.freeuk.com/misacham/temp/error.htm

It's clear that the UPDATE SQL isn't being created correctly. Would it
make more sense to attempt to write the UPDATE manually?

Any feedback would be appreciated, thanks.

- Triffid


Dec 16 '07 #1
2 1708
Hi Triffid,

you can refer to the code below to update your database using the coommand
builder by generating the update command automatically.

protected void Button1_Click(object sender, EventArgs e)
{
string connstr = "provider = SQLOLEDB; data source =
in-ts-manish\\sqlexpress; integrated security = SSPI; database = pubs";
OleDbConnection myconn = new OleDbConnection(connstr);
// Create a dataset.
DataSet ds = new DataSet();
// Create dataadapters for each tables.
OleDbDataAdapter myadpt = new OleDbDataAdapter("select *
from dbo.authors", myconn);
myadpt.Fill(ds,"authors");

ds.Tables["authors"].Rows[1]["au_lname"] = "Singhal";
OleDbCommandBuilder scb = new OleDbCommandBuilder(myadpt);
myadpt.UpdateCommand = scb.GetUpdateCommand();
myadpt.Update(ds,"authors");

this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}

Regards,
Manish
www.componentone.com

"tr*****@oink.co.uk" wrote:
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 obvious,
but having searched for quite a while, I don't know what it is(!)

The code is here (intentionally showing source rather than having
server run page):-
http://home.freeuk.com/misacham/temp...ER_UPDATE.aspx
and this is the Access DB I'm using:-
http://home.freeuk.com/misacham/temp/writable.mdb

(I considered pasting the whole longwinded thing here, but wasn't sure
that this would be a good idea.)

Here's what happens when I try to run it on my local Windows XP
machine ("Syntax error in UPDATE statement", apparently because UPDATE
statement is null):-
http://home.freeuk.com/misacham/temp/error.htm

It's clear that the UPDATE SQL isn't being created correctly. Would it
make more sense to attempt to write the UPDATE manually?

Any feedback would be appreciated, thanks.

- Triffid


Dec 17 '07 #2
On 17 Dec, 10:00, Manish <Man...@discussions.microsoft.comwrote:
HiTriffid,

you can refer to the code below to update your database using the coommand
builder by generating the update command automatically.
Thanks for the feedback; I adapted your code for my situation (using
my Access/Jet DB instead of SQL Server).

Although it overcame the problem I was having, unfortunately it then
ran into the exact same problem I had the last time I tried
OleDbCommandBuilder (now I remember...).

Specifically, it complained about syntax errors in the generated SQL.
Doing a Google on this problem, it seemed that it had something to do
with field names containing spaces. So I renamed all the fields in the
database, updated the code, and.... it seems to work.

Either OleDbCommandBuilder isn't particularly smart and requires
convoluted workarounds, or I've missed something, but I'm going to
look into this sometime.

Anyway, thanks for your help- at least I'm halfway there next time :)

- Triffid

Dec 18 '07 #3

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

Similar topics

5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
2
by: Lori Markle via .NET 247 | last post by:
Hi, I already posted this but can't find it anywhere! I'm having a problem that seems very simple. I'm trying to updatea db and am getting stuck on the data binding of a textbox. Iget a "Cannot...
12
by: Gary Paris | last post by:
I have enclosed the sample code that I created. I want to read in employee data, and modify a few fields. I have tried to globally declare the objects that I need but I still am having problems. ...
1
by: johnb41 | last post by:
I have a datagrid that successfully allows editing and updating (with dataadapter.update command). I want the user to be able to edit the "text" in the datagrid, but i DON'T want the user to be...
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...
7
by: Paul | last post by:
I'm trying to update a Microsoft Access database. I can successfully read from the database and submit a command to DELETE all records from a table. Now I'm trying to add records to the table...
8
by: Nimion | last post by:
Im getting the "Syntax error in INSERT INTO statement." at my da.Update(ds, "Expenses") line in code... heres my full code to follow. ...
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: JB | last post by:
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...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.