D
daveL
Hello
I have a Windows Form with Controls
when the user clicks the save button
I place the Controls Values into a DataRow
this Row is then added To a DataTable with (dtTmp)
Row count of 1
I Set up DataAdapter with the update command and insertCommand
and it Inserts a new Row into the physical Table when its a Existing Row
with a identity Column
if I issue dtTmp.AcceptChanges() , then it does not insert, But it does not
do the Update
dtTmp is Cleared after each Write its used to insert or update depending
whether the user is adding or editing
so it always has a new row in it , with count of 1.
below is Code im Using
dtTmp.Clear();
dtTmp.Rows.Add(this.oRow)
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = new SqlCommand("select Top 0 * 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) // creates duplicate row if dttmp.acceptchanges() not
issued this row does exist in physical table
DaveL
I have a Windows Form with Controls
when the user clicks the save button
I place the Controls Values into a DataRow
this Row is then added To a DataTable with (dtTmp)
Row count of 1
I Set up DataAdapter with the update command and insertCommand
and it Inserts a new Row into the physical Table when its a Existing Row
with a identity Column
if I issue dtTmp.AcceptChanges() , then it does not insert, But it does not
do the Update
dtTmp is Cleared after each Write its used to insert or update depending
whether the user is adding or editing
so it always has a new row in it , with count of 1.
below is Code im Using
dtTmp.Clear();
dtTmp.Rows.Add(this.oRow)
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = new SqlCommand("select Top 0 * 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) // creates duplicate row if dttmp.acceptchanges() not
issued this row does exist in physical table
DaveL