I have a program for msaccess 2007 and VS 2010, every thing working correctly except saving the data to the database. by the way its reading correctly from the dbase
Here is the code:
Add new record:
private void button4_Click(object sender, EventArgs e)
{
f1.Text = "";
f2.Text = "";
newCustomersRow = pharmaDataSet.Tables["drugType"].NewRow();
newCustomersRow["DName"] = f1.Text.ToString();
newCustomersRow["Description"] = f2.Text.ToString();
pharmaDataSet.Tables["drugType"].Rows.Add(newCustomersRow);
drugTypeBindingSource.MoveLast();
DataGridViewDataErrorContexts cntxt = new DataGridViewDataErrorContexts();
dg.CommitEdit(cntxt);
drugTypeBindingSource.MoveLast();
f1.Text = "";
f2.Text = "";
}
Delete record:
private void button3_Click(object sender, EventArgs e)
{
try
{
drugTypeBindingSource.RemoveCurrent();
}
catch (Exception)
{
}
}
Save to DBase
private void button2_Click(object sender, EventArgs e)
{
this.Validate();
this.drugTypeBindingSource.EndEdit();
tableAdapterManager.UpdateAll(pharmaDataSet);
/*
* drugTypeBindingSource.DataSource = pharmaDataSet.drugType;
dg.DataSource = drugTypeBindingSource;
drugTypeTableAdapter.Update(pharmaDataSet.drugType);
*/
drugTypeTableAdapter.Update(pharmaDataSet.drugType);
pharmaDataSet.drugType.AcceptChanges();
ActiveForm.Close();
// tableAdapterManager.UpdateAll(pharmaDataSet);
}
private void ff_TextChanged(object sender, EventArgs e)
{
try
{
// customerCreditBindingSource BindingSource myBindingSource;
//dg.DataSource = drugTypeBindingSource;
//drugTypeBindingSource.DataSource = pharmaDataSet;
//drugTypeBindingSource.DataMember = pharmaDataSet.Tables[2].TableName;
drugTypeBindingSource.Filter = "DName Like '" + ff.Text + "%'";
// button2.Visible = false;
// button4.Visible = false;
}
catch (Exception) { }
}
Yusif WassalPosted Oct 13, 2012, 3:14 PM
concurrency violation the updatecommand affected 0 of the expected 1 records
in the method updateAll
Yusif WassalPosted Oct 13, 2012, 1:45 PM
Nitesh KejriwalPosted Oct 13, 2012, 10:00 AM
Yusif WassalPosted Oct 13, 2012, 8:19 AM
but does not effect the database
Yusif WassalPosted Oct 13, 2012, 8:17 AM
I add the method, so it ll looks like that:
But has not affect also
Nitesh KejriwalPosted Oct 13, 2012, 3:03 AM
Yusif WassalPosted Oct 12, 2012, 8:25 PM
pharmaDataSet.drugType.AcceptChanges();
if I am wrong then please tell me the correct method to commit the dbase
Nitesh KejriwalPosted Oct 12, 2012, 4:50 AM