SqlDataAdapter

D

daveL

hello below is my sqldatadapter setup
it is inserting a row when it should be updating a row
can you tell me what the problem is



SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = new SqlCommand("select * from users order
by userid");
ad.SelectCommand.Connection = this.SqlConn1.Conn;
SqlCommandBuilder cmd = new SqlCommandBuilder(ad);
ad.InsertCommand = cmd.GetInsertCommand();
ad.UpdateCommand = cmd.GetUpdateCommand();
ad.UpdateCommand.Connection = this.SqlConn1.Conn;
ad.InsertCommand.Connection = this.SqlConn1.Conn;
ad.UpdateCommand.Parameters.Add("@Userid", SqlDbType.Int);
ad.UpdateCommand.Parameters["@UserId"].SourceColumn =
"UserId";

ad.Update(dtTmp) // dtTmp has 1 row (datatable)
 
D

DaveL

I got it
My dtTmp (tmp table)
i fill datarow with window control .Text
then add to the dtTmp Table....

I did not issue dt.AcceptChanges()
and SqlDataAdapter thought i was adding a new row

Now i have a brain ach, that took a while to find

DaveL
 

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