Understanding updating a Dataset when bound to multiple TextBoxes

  • Thread starter Thread starter Sam Carleton
  • Start date Start date
S

Sam Carleton

I have followed the "Walkthrough: Displaying Data in a Windows
Form Using a Parameterized Query" and would like to modify it to
update the row being displayed.

If you are not familiar with the walkthrough, it is very simply.
You setup a Data Connection, then a Data Adapter, and finally a
Dataset. Then you add a few textboxes to the form and bind them
to the Dataset columns. One of the textboxes (txtStateParameter )
is for the user to enter the state id to lookup the specific.
Here is the only actuall code from the walkthrough, to this point:

private void btnShow_Click(object sender, System.EventArgs e)
{
oleDbDataAdapter1.SelectCommand.Parameters["state"].Value = txtStateParameter.Text;
dsAuthors1.Clear();
oleDbDataAdapter1.Fill(dsAuthors1);
}

The question I have now is how do I update this row when the user
changes something on the form and clicks the save button? I have
seen others posting stating that with textboxes, one must first
call the BeginEdit() and EndEdit(). I dug around and found these
methods on the DataRow object. At this point, I don't have a
DataRow, only a Dataset.

Can anyone fill me in on what I am missing? Thanks!

Sam
 
Hi Sam,
I have followed the "Walkthrough: Displaying Data in a Windows
Form Using a Parameterized Query" and would like to modify it to
update the row being displayed.

If you are not familiar with the walkthrough, it is very simply.
You setup a Data Connection, then a Data Adapter, and finally a
Dataset. Then you add a few textboxes to the form and bind them
to the Dataset columns. One of the textboxes (txtStateParameter )
is for the user to enter the state id to lookup the specific.
Here is the only actuall code from the walkthrough, to this point:

private void btnShow_Click(object sender, System.EventArgs e)
{
oleDbDataAdapter1.SelectCommand.Parameters["state"].Value =
txtStateParameter.Text;
dsAuthors1.Clear();
oleDbDataAdapter1.Fill(dsAuthors1);
}

The question I have now is how do I update this row when the user
changes something on the form and clicks the save button? I have
seen others posting stating that with textboxes, one must first
call the BeginEdit() and EndEdit(). I dug around and found these
methods on the DataRow object. At this point, I don't have a
DataRow, only a Dataset.

Inside the DataSet resides an object called DataTable which contains your
data (this is always the case). Inside this DataTable there's the dataRows.

However, if your fields are bound to the dataset, it should be easy ... you
just habe to call oleDbDataAdapter1.Update(), since the data should already
be inside the dataset.

Regards,

Frank Eller
 
Back
Top