da.Update not working - nothing in Sql Profiler - stumped :(

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've been beating my head against the wall for a couple days now, and am
completely stumped.

I have a datagrid in a windows form which is bound to a strongly typed
dataset named MainCases. The dataset is a public static object in Class1.
when the form loads the SqlDataAdapter fills MainCases from its SQL 2000
parent table, tblMainCases. The user is able to make changes, when they hit
"save" it runs the following function.

The code runs without error, but has no effect on the master table either on
Insert or Delete. Sql Profiler doesn't show T-SQL statements INSERT or UPDATE
statements running against the database.

Any advice would be highly appreciated at this point. Thanks in advance!

Ande



private void UpdateCases()
{
Class1.myDS.MainCases.AcceptChanges();

//UPDATE
string sSQL = "UPDATE tblMainCases " +
"SET Role = @Role, Type = @Type, CaseNumber = @CaseNumber, Date = @Date,
OppParty = @OppParty, OppCounsel = @OppCounsel, Summary = @Summary " +
"WHERE Counter = @Counter;";

Class1.da.UpdateCommand = new SqlCommand(sSQL, Class1.cn);

Class1.da.UpdateCommand.Parameters.Add("@Counter", SqlDbType.Int, 8,
"Counter");
Class1.da.UpdateCommand.Parameters.Add("@Role", SqlDbType.VarChar, 50,
"Role");
Class1.da.UpdateCommand.Parameters.Add("@Type", SqlDbType.VarChar, 50,
"Type");
Class1.da.UpdateCommand.Parameters.Add("@CaseNumber", SqlDbType.VarChar,
50, "CaseNumber");
Class1.da.UpdateCommand.Parameters.Add("@Date", SqlDbType.DateTime, 8,
"Date");
Class1.da.UpdateCommand.Parameters.Add("@OppParty", SqlDbType.VarChar,
50, "OppParty");
Class1.da.UpdateCommand.Parameters.Add("@OppCounsel", SqlDbType.VarChar,
50, "OppCounsel");
Class1.da.UpdateCommand.Parameters.Add("@Summary", SqlDbType.Text, 16,
"Summary");

//INSERT
sSQL = "INSERT INTO tblMainCases (AccountKey, Role, Type, CaseNumber,
Date, OppParty, OppCounsel, Summary) " +
"VALUES (@AccountKey, @Role, @Type, @CaseNumber, @Date, @OppParty,
@OppCounsel, @Summary);";

Class1.da.InsertCommand = new SqlCommand(sSQL, Class1.cn);
Class1.da.InsertCommand.Parameters.Add("@AccountKey", SqlDbType.Int, 4,
"AccountKey");
Class1.da.InsertCommand.Parameters.Add("@Role", SqlDbType.VarChar, 12,
"Role");
Class1.da.InsertCommand.Parameters.Add("@Type", SqlDbType.VarChar, 50,
"Type");
Class1.da.InsertCommand.Parameters.Add("@CaseNumber", SqlDbType.VarChar,
50, "CaseNumber");
Class1.da.InsertCommand.Parameters.Add("@Date", SqlDbType.DateTime, 8,
"Date");
Class1.da.InsertCommand.Parameters.Add("@OppParty", SqlDbType.VarChar,
50, "OppParty");
Class1.da.InsertCommand.Parameters.Add("@OppCounsel", SqlDbType.VarChar,
50, "OppCounsel");
Class1.da.InsertCommand.Parameters.Add("@Summary", SqlDbType.Text, 16,
"Summary");

Class1.da.Update(Class1.myDS.MainCases);
}
 
I should add that the RowsAffected value for the update and insert commands
is -1, even after I've changed items on the datagrid and can verify those
changes by serializing the database to a textfile (Class1.myDS.WriteXml) in
debug mode.

Please let me know if you can think what I'm doing wrong.

Thanks!

Andre
 
Andre Ranieri said:
I've been beating my head against the wall for a couple days now, and am
completely stumped.

I have a datagrid in a windows form which is bound to a strongly typed
dataset named MainCases. The dataset is a public static object in Class1.
when the form loads the SqlDataAdapter fills MainCases from its SQL 2000
parent table, tblMainCases. The user is able to make changes, when they
hit
"save" it runs the following function.

The code runs without error, but has no effect on the master table either
on
Insert or Delete. Sql Profiler doesn't show T-SQL statements INSERT or
UPDATE
statements running against the database.

Any advice would be highly appreciated at this point. Thanks in advance!

Ande



private void UpdateCases()
{
Class1.myDS.MainCases.AcceptChanges();

AcceptChanges changes all the inserted, delted and updated rows to
unchanged. So the DataSet has no changed rows to mashall to the datase.
DataAdapter.Update() will invoke DataSet.AcceptChanges() after it completes.

David
 
Thanks for your reply.

I've tried taking out the AcceptChanges line and it still doesn't work.

I've tried adding RowUpdated and RowUpdating handlers to the SqlDataAdapter,
but they don't appear to be firing.
 
Dave,

I went back through my code and found another instance of AcceptChanges in a
different function. It works now, thanks for your help!
 
Back
Top