ADO.NET binding problem...

  • Thread starter Thread starter Katie
  • Start date Start date
K

Katie

hi,

im having a problem commiting edits to my database. in the form load i
select the record to edit. i bind my text controls. then after i manually
edit my text in the text boxes i press the save button. the edits dont take.

when i click the save button i tell the dataset to accept changes from the
bound controls then call the update command. however, none of the changes
take. the bound text boxes do show the data for the row before editing so
they are bound but after i edit the text and click the save button no errors
and no changes occur. have i left something out?

any ideas?

---form load
dsDataSet = new DataSet();
daDataAdapter = new AsaDataAdapter("SELECT PK, Destination, Contain, Code
FROM items WHERE PK = " + mPKID.ToString() , conn);
daDataAdapter.Fill(dsDataSet, "items");
CboDestination.DataSource = dsDataSet.Tables["items"];
CboDestination.DisplayMember = "Destination";
//textBoxes - Simple Binding:
TxtContains.DataBindings.Add("Text",dsDataSet.Tables["items"],"Contain");
TxtBarcode.DataBindings.Add("Text",dsDataSet.Tables["items"],"Code");


---save button click
dsDataSet.Tables["items"].AcceptChanges();
daDataAdapter.UpdateCommand = new AsaCommand("UPDATE items SET PK = @PK,
Destination = @Destination, Contain = @Contain, Code = @Code, Timestamp =
@Timestamp WHERE PK = @PK", conn);
daDataAdapter.UpdateCommand.Parameters.Add("@PK",AsaDbType.Integer);
daDataAdapter.UpdateCommand.Parameters.Add("@Destination",AsaDbType.Char);
daDataAdapter.UpdateCommand.Parameters.Add("@Contain",AsaDbType.Float);
daDataAdapter.UpdateCommand.Parameters.Add("@Code",AsaDbType.Integer);
daDataAdapter.UpdateCommand.Parameters.Add("@TimeStamp",AsaDbType.TimeStamp)
;
daDataAdapter.Update(dsDataSet,"items");
 
Don't accept changes in the DataSet before calling update - the update
function will only operate on records which are changed in the dataset -
calling AcceptChanges marks all records as current so no Inserts, Deletes or
Updates will be carried out. Calling DataAdapter.Update will by default mark
the changes as accepted in the DataSet once the update method has completed.

Peter
 
If i move AcceptChanges... after the daDataAdapter.Update... i get the same
results.
It's odd because if i check the RowState after my manual edits but before
update... and accept... the row state says "Unchanged".

however, if i loop through the row items i see my changes (as shown below)

MessageBox.Show (dtDataTable.Rows[0].RowState.ToString());
for (int n = 0;n < 5;n++)
{
MessageBox.Show (dtDataTable.Rows[0].ItemArray[n].ToString());
}

It looks like the changes are in the table but the RowState doesn't know
about it...

any ideas?

Peter Foot said:
Don't accept changes in the DataSet before calling update - the update
function will only operate on records which are changed in the dataset -
calling AcceptChanges marks all records as current so no Inserts, Deletes or
Updates will be carried out. Calling DataAdapter.Update will by default mark
the changes as accepted in the DataSet once the update method has completed.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

Katie said:
hi,

im having a problem commiting edits to my database. in the form load i
select the record to edit. i bind my text controls. then after i manually
edit my text in the text boxes i press the save button. the edits dont take.

when i click the save button i tell the dataset to accept changes from the
bound controls then call the update command. however, none of the changes
take. the bound text boxes do show the data for the row before editing so
they are bound but after i edit the text and click the save button no errors
and no changes occur. have i left something out?

any ideas?

---form load
dsDataSet = new DataSet();
daDataAdapter = new AsaDataAdapter("SELECT PK, Destination, Contain, Code
FROM items WHERE PK = " + mPKID.ToString() , conn);
daDataAdapter.Fill(dsDataSet, "items");
CboDestination.DataSource = dsDataSet.Tables["items"];
CboDestination.DisplayMember = "Destination";
//textBoxes - Simple Binding:
TxtContains.DataBindings.Add("Text",dsDataSet.Tables["items"],"Contain");
TxtBarcode.DataBindings.Add("Text",dsDataSet.Tables["items"],"Code");


---save button click
dsDataSet.Tables["items"].AcceptChanges();
daDataAdapter.UpdateCommand = new AsaCommand("UPDATE items SET PK = @PK,
Destination = @Destination, Contain = @Contain, Code = @Code, Timestamp =
@Timestamp WHERE PK = @PK", conn);
daDataAdapter.UpdateCommand.Parameters.Add("@PK",AsaDbType.Integer);
daDataAdapter.UpdateCommand.Parameters.Add("@Destination",AsaDbType.Char);
daDataAdapter.UpdateCommand.Parameters.Add("@Contain",AsaDbType.Float);
daDataAdapter.UpdateCommand.Parameters.Add("@Code",AsaDbType.Integer);
daDataAdapter.UpdateCommand.Parameters.Add("@TimeStamp",AsaDbType.TimeStamp)
;
daDataAdapter.Update(dsDataSet,"items");
 
can you please include a simple program that reproduces this problem so we
can troubleshoot further?

Thanks.
 
Back
Top