I am a DB programming noob. I need to populate a DB from textbox fields but when I try to then commit it to the DB, I go and view the database and all I see is Nulls… nothing is being saved… please help..
thanks
private void btnSubmit_Click(object sender, EventArgs e)
{
TradesDataSet.TradesRow newTradesRow = tradesDataSet.Trades.NewTradesRow();
newTradesRow.ID = textBoxTradeID.Text;
newTradesRow.EntryPrice = textBoxEntryPrice.Text;
newTradesRow.ExitPrice = textBoxExitPrice.Text;
tradesDataSet.Trades.Rows.Add(newTradesRow);
tradesDataSet.Trades.AcceptChanges();
try
{
this.Validate();
this.tradesBindingSource.EndEdit();
this.tradesTableAdapter.Update(this.tradesDataSet.Trades);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}
}
Remove the
AcceptChangescall. Data adapter’sUpdatemethod looks at the changes in the database and uses the change list to update the actual database. It automatically accepts the changes in theDataSetafter the update. If you callAcceptChangeson theDataSetmanually before updating, theDataAdapterwill think nothing is changed and doesn’t do anything.