SqlCommandBuilder unable to Update a dataset

C

caldera

I am using SqlCommandBuilder to update,insert,delete my data. I can do for insert and
delete. My code is

string sql=" select * from "+dbname;
SqlDataAdapter sdata=new SqlDataAdapter();
sdata.SelectCommand=new SqlCommand(sql,scon);
SqlCommandBuilder scom=new SqlCommandBuilder(sdata);
sdata.UpdateCommand=scom.GetUpdateCommand();
sdata.RowUpdating+=new SqlRowUpdatingEventHandler(sdata_RowUpdating);
sdata.RowUpdated+=new SqlRowUpdatedEventHandler(sdata_RowUpdated);
sdata.Update(ds,dbname);
but when I reach the SqlRowUpdating Event my event argument command is undefined. But my
dataadapter take the update command correctly.
How can I solve this problem
Thanks for all.
 
W

William Ryan eMVP

When you say it's undefined, what is happening? From the subject of your
post I take it the update is not working ie nothing is being updated in the
db? You said the Adapter is taking the Update command fine - is that to say
that no exceptions are being raised or simply that you can specify an update
command? If you call update and nothing happens to the db but no exception
is thrown, the first thing to do is verify that the dataset's HasChanges is
true. If it is not, then your problem is that none of your edits are being
seen. You can probably resolve this by using EndCurrentEdit. However if
Haschanges is true then you want to check the table and verify that you have
a Primary Key and that it's included in your Select statement. You'll also
want to make sure that you have no reserved words in your table's field
names. You may need to set the QuoteSuffix and .QuotePrefix properties
(usually to [ and ] respectively) Also verify that you aren't raising any
exceptions and just eating them.. that you're using some sort of
notification for exceptions.

Sometimes when Access doesn't have the appropriate permisssions then it
won't allow writes (just an FYI for general knowledge- you aare using
SqlServver so this isn't the problem - althogh verifying that you have the
corect permissons is always a pretty good idea.

If none of this helps let me know and I'll see what we can do from there.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
C

caldera

Thank you. I solved the problem. As you said, my problem is related to edit the dataset. I change the values using ds.Tables[0].Row[0].ItemArray[1]= it doesn't change the rowversion of the dataset. I use a datarow associated to this row then edit the dataset. Then rowversion was changed.
Thanks for your answer.

When you say it's undefined, what is happening? From the subject of your
post I take it the update is not working ie nothing is being updated in the
db? You said the Adapter is taking the Update command fine - is that to say
that no exceptions are being raised or simply that you can specify an update
command? If you call update and nothing happens to the db but no exception
is thrown, the first thing to do is verify that the dataset's HasChanges is
true. If it is not, then your problem is that none of your edits are being
seen. You can probably resolve this by using EndCurrentEdit. However if
Haschanges is true then you want to check the table and verify that you have
a Primary Key and that it's included in your Select statement. You'll also
want to make sure that you have no reserved words in your table's field
names. You may need to set the QuoteSuffix and .QuotePrefix properties
(usually to [ and ] respectively) Also verify that you aren't raising any
exceptions and just eating them.. that you're using some sort of
notification for exceptions.

Sometimes when Access doesn't have the appropriate permisssions then it
won't allow writes (just an FYI for general knowledge- you aare using
SqlServver so this isn't the problem - althogh verifying that you have the
corect permissons is always a pretty good idea.

If none of this helps let me know and I'll see what we can do from there.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 

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