Databound Textbox - DataSet not getting updated value

  • Thread starter Thread starter John Rose
  • Start date Start date
J

John Rose

I have one databound TextBox on a page with one button. The TextBox loads
the correct SQL record data but typing a new string into the Textbox fails
to change the DataSet. Any ideas? There must be some way to force the
edited TextBox to update the DataSet since it appears to not be done
automatically.

//--------------------------------------------------------------------------
--------------------------
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dataSet21);
Page.DataBind();
}
//--------------------------------------------------------------------------
--------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
//dataSet21.AcceptChanges();
DataSet ds = dataSet21.GetChanges();
sqlDataAdapter1.Update(dataSet21);
}
//--------------------------------------------------------------------------
--------------------------
 
How do you do that?

Actually the Button1_Click event is:
//---------------------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Update(dataSet21);
}
//---------------------------------------


Scott M. said:
Where are you taking the data from the textbox and placing it into the
dataset?


John Rose said:
I have one databound TextBox on a page with one button. The TextBox loads
the correct SQL record data but typing a new string into the Textbox fails
to change the DataSet. Any ideas? There must be some way to force the
edited TextBox to update the DataSet since it appears to not be done
automatically.
//--------------------------------------------------------------------------
--------------------------
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(dataSet21);
Page.DataBind();
}
//--------------------------------------------------------------------------
--------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
//dataSet21.AcceptChanges();
DataSet ds = dataSet21.GetChanges();
sqlDataAdapter1.Update(dataSet21);
}
//--------------------------------------------------------------------------
 
You've got to place the text value into the dataset column for a given
row...

DataSet.Tables("tableName").Rows(whichRowToWorkWith).Item("columnName") =
textbox.text

You also need to make sure your DataAdapter has a valid (and correct)
update, delete and insert statement associated with its commands.

The fact that the textbox is bound does not mean that if you change its
value the dataset will immediately change, you have to manually update the
dataset with the value from the textbox.



John Rose said:
How do you do that?

Actually the Button1_Click event is:
//---------------------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Update(dataSet21);
}
//---------------------------------------


Scott M. said:
Where are you taking the data from the textbox and placing it into the
dataset?
//--------------------------------------------------------------------------//--------------------------------------------------------------------------//--------------------------------------------------------------------------
 
Thanks. Looks like in C# I have to do:

private void Button1_Click(object sender, System.EventArgs e)
{
dataSet21.Tables["tablename"].Rows[intRow].BeginEdit();
dataSet21.Tables["tablename"].Rows[intRow]["columnname"] = textbox.Text;
dataSet21.Tables["tablename"].Rows[intRow].EndEdit();
sqlDataAdapter1.Update(dataSet21);
}
 
Back
Top