0

I have a problem when i m run my code then updating is successful but I want to update only one row . when through my code all data is update .

My code is:

Code

protected void imgbtn_Save_Click(object sender, EventArgs e)
{

        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandText = "update Companies set CompanyFName='" + txt_ComName.Text + "',CompanySName='" + txt_ShortName.Text + "',CompanyeMail='" + txt_email.Text + "',CompanyWebsite='" + txt_website.Text + "'where CompanyId=CompanyId";

        cmd.Connection = conn;
        OleDbDataAdapter da = new OleDbDataAdapter();
        da.UpdateCommand = cmd;

        cmd.ExecuteNonQuery();
        conn.Close();
        BindGridData();
        lblError.Font.Bold = true;
        lblError.Font.Size = 11;
        lblError.Text = "You have successfully modified the case!";
    }

I don't know why?

Plz suggest me.

"Thanks"

Sanat Pandey
  • 4,081
  • 17
  • 75
  • 132

1 Answers1

0

First use OleDbParameter. Check out this thread. how to update a table using oledb parameters?.

The problem with your code is that you are refreshing the complete data source using BindGridData(); There may be instances where other records are updated somewhere else in the code and it seems that your BindGridData() is getting data from the database again. You may store the existing data source in a temp location and then update it and bind it to the data grid instead of getting latest through db

Community
  • 1
  • 1
Habib
  • 219,104
  • 29
  • 407
  • 436