none
updating database problems RRS feed

  • Question

  • Hi there

    I have a problem with updating my database,  I can insert data fine in the database but when I want to update it does not work. Here's my code below .Please tell mi what im doing wrong.

     

     

     

    private void btnUpdate_Click(object sender, EventArgs e)

    {

    string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb";

    OleDbCommand command = new OleDbCommand();

    string bhala = "Update Table1 Set CompanyName ='"+txtCompany.Text+"' where CompanyName = '" + txtCompany.Text + "'";

    OleDbConnection datatryConn = new OleDbConnection(strConnection);

    datatryConn.Open();

    OleDbDataAdapter da = new OleDbDataAdapter(bhala, datatryConn);

    //DataSet ds = new DataSet();

    DataRow r = datatryds.Tables["Table1"].NewRow();

     

    datatryds.Tables["Table1"].Rows.Find(r);

    r.BeginEdit();

    r["CompanyName"] = txtCompany.Text;

    r.EndEdit();

    if (datatryds.HasChanges())

    {

    da.Update(datatryds, "Table1");

    datatryds.AcceptChanges();

    }

    OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(da);

    datatryConn.Close();

    MessageBox.Show("Updated successfully!");

    }

     

     

    Any help will be appreciated

    Thank you in advance

    Csanda

    Thursday, September 6, 2007 12:50 PM

All replies

  • hii

     I think u have gone a very long way to do the update. But still do you have any exception thrown on running the code !

     

    Thursday, September 6, 2007 2:39 PM