Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Problems with OleDbCommandBuilder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
triffid@oink.co.uk - 16 Dec 2007 17:09 GMT
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/ASPX_COMMAND_BUILDER_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
Manish - 17 Dec 2007 10:00 GMT
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

> Hi there,
>
[quoted text clipped - 23 lines]
>
> - Triffid
triffid@oink.co.uk - 18 Dec 2007 21:27 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.