Databound Textbox - DataSet not getting updated value

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);
}
//--------------------------------------------------------------------------
--------------------------
 
J

John Rose

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);
}
//--------------------------------------------------------------------------
 
S

Scott M.

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?
//--------------------------------------------------------------------------//--------------------------------------------------------------------------//--------------------------------------------------------------------------
 
J

John Rose

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top