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

Nitesh KejriwalRank #253 · 9.9K reputationPosted Oct 12, 2012, 12:50 AM EDT
Yusif Wassal12 reputationPosted Oct 12, 2012, 4:25 PM EDT
pharmaDataSet.drugType.AcceptChanges();
if I am wrong then please tell me the correct method to commit the dbase
Nitesh KejriwalRank #253 · 9.9K reputationPosted Oct 12, 2012, 11:03 PM EDT
Yusif Wassal12 reputationPosted Oct 13, 2012, 4:17 AM EDT
I add the method, so it ll looks like that:
But has not affect also
Yusif Wassal12 reputationPosted Oct 13, 2012, 4:19 AM EDT
but does not effect the database
Nitesh KejriwalRank #253 · 9.9K reputationPosted Oct 13, 2012, 6:00 AM EDT
Yusif Wassal12 reputationPosted Oct 13, 2012, 9:45 AM EDT
Yusif Wassal12 reputationPosted Oct 13, 2012, 11:14 AM EDT
concurrency violation the updatecommand affected 0 of the expected 1 records
in the method updateAll