Yusif Wassal

Yusif Wassal

  • NA
  • 12
  • 2.7k

Visual Controls How to effect Database

Oct 12 2012 2:56 AM
Hello,

I am using visual components to build a program with VS 2010 C# and MS Access.
It working well except it does not effect the database while it reads correctly from database.

here us some of the code

for saving to database:
private void button2_Click(object sender, EventArgs e)
        {
        
            this.Validate();
            this.drugTypeBindingSource.EndEdit();
            
            
            tableAdapterManager.UpdateAll(pharmaDataSet);
       }


for 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 = "";           
        
        }


for delete :
 private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                drugTypeBindingSource.RemoveCurrent();
            }
            catch (Exception)
            {

            }
        }