I am using Sqltransation to update data from sourcedt to datatable table. Below two lines, first I am merging data from clonedt to sourcedt. Then trying to update it to database table.
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlTransaction trans = con.BeginTransaction();
SqlCommand cmd = new SqlCommand(strCommand, con, trans)
SqlDataAdapter da = new SqlDataAdapter(cmd)
SqlCommandBuilder cmb = new SqlCommandBuilder(da);
da.InsertCommand = cmb.GetInsertCommand();
da.UpdateCommand = cmb.GetUpdateCommand();
da.InsertCommand.Transaction = trans;
da.UpdateCommand.Transaction = trans;
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(sourceDt);
sourceDt.Merge(clonedDt, false, MissingSchemaAction.AddWithKey);
int count = da.Update(sourceDt);
trans.Commit(); //Commit the changes to database
The rest of the code is fine, issue seems to be in this commit statement only. How should I find whats wrong?