DataAdapter.Update isn't doing anything

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a really simple application for inserting/updating record in a table.
The app uses a sqlConnection, sqlDataAdapter and a dataset.

I bind the fields to text boxes and a grid to allow for the insert/editing.
I also have a button that does a Table.NewRow() and another to do the save.
I tried using sqlDataAdapter1.Update(dataset11) but nothing seems to change.
No new records, no errors.

I'm sure this is really easy and I'm probably just missing something here.
 
Hi,

Could you supply some code showing what your doing? will make it easier if i
can see what your trying to do.

Regards

Darryn
 
Sorry - should have posted this:

I also have a datagrid on the form which uses the same dataSet11.Tables[0]
datasource.

I actually noticed some other strange things like when I click the new
button, a new row is returned but the count for the currencyManager doesn't
increase and a new row is NOT added to the grid.
If I click on the last row in the grid and hit the down arrow to add a row,
I can enter the values but they don't get saved. If I do it again, another
row is added but when I exit a field it changes the value to null.

private void Form1_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(this.dataSet11);
sqlDataAdapter2.Fill(this.dataSet11);
BindControls(dataSet11.Tables[0] );
}

private void BindControls(DataTable table)
{
textBox1.DataBindings.Add("Text", table, "Name");
textBox2.DataBindings.Add("Text", table, "Desc");
textBox7.DataBindings.Add("Text", table, "ModelNum");

this.m_currencyManager = (CurrencyManager)this.BindingContext
;
m_currencyManager.Position = 0;
}

private void New_Click(object sender, System.EventArgs e)
{
DataRow dr = this.dataSet11.Tables["Products"].NewRow();
dataSet11.Products.Rows.Add(dr);
m_currencyManager.Position = this.m_currencyManager.Count - 1;
}

private void Save_Click(object sender, System.EventArgs e)
{
DataSet changed = dataSet11.GetChanges();

if (changed == null)
return;

sqlDataAdapter1.InsertCommand.Connection.Open();
int rows = sqlDataAdapter1.Update(changed);
dataSet11.AcceptChanges();
}
 
Instantiate a CommandBuilder class and associate it with the sqlDataAdapter
object.
-Vish.

Joe said:
Sorry - should have posted this:

I also have a datagrid on the form which uses the same dataSet11.Tables[0]
datasource.

I actually noticed some other strange things like when I click the new
button, a new row is returned but the count for the currencyManager doesn't
increase and a new row is NOT added to the grid.
If I click on the last row in the grid and hit the down arrow to add a row,
I can enter the values but they don't get saved. If I do it again, another
row is added but when I exit a field it changes the value to null.

private void Form1_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(this.dataSet11);
sqlDataAdapter2.Fill(this.dataSet11);
BindControls(dataSet11.Tables[0] );
}

private void BindControls(DataTable table)
{
textBox1.DataBindings.Add("Text", table, "Name");
textBox2.DataBindings.Add("Text", table, "Desc");
textBox7.DataBindings.Add("Text", table, "ModelNum");

this.m_currencyManager = (CurrencyManager)this.BindingContext
;
m_currencyManager.Position = 0;
}

private void New_Click(object sender, System.EventArgs e)
{
DataRow dr = this.dataSet11.Tables["Products"].NewRow();
dataSet11.Products.Rows.Add(dr);
m_currencyManager.Position = this.m_currencyManager.Count - 1;
}

private void Save_Click(object sender, System.EventArgs e)
{
DataSet changed = dataSet11.GetChanges();

if (changed == null)
return;

sqlDataAdapter1.InsertCommand.Connection.Open();
int rows = sqlDataAdapter1.Update(changed);
dataSet11.AcceptChanges();
}

Darryn Ross said:
Hi,

Could you supply some code showing what your doing? will make it easier if i
can see what your trying to do.

Regards

Darryn
 
Back
Top