Click here to Skip to main content
15,895,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why error is given in the website when I uploaded the source file.
Please instruct me for this.

Error - Operation must use an updateable query.

My Code for update is looking like given below
C#
void submit(Object sender, EventArgs e)
{
  con.Open();
  string va=d1.SelectedItem.Value;
  com=con.CreateCommand();
  com.CommandText="UPDATE notification SET notice = '" + ta1.Value.Replace("\'","\'\'") + "' where id='" + va + "'";
  //com.CommandText="UPDATE notification SET notice = '" + ta1.Value + "' where id='" + va + "'";
  try
  {
    com.ExecuteNonQuery();
    System.Web.UI.WebControls.Label lbl1=new System.Web.UI.WebControls.Label();
    lbl1.ForeColor=System.Drawing.Color.Yellow;
    lbl1.BackColor=System.Drawing.Color.Blue;
    lbl1.Text="Your record SUBMITED sucessfully";
    ph1.Controls.Add(lbl1);
  }
  catch(Exception ex)
  {
    Response.Write(ex.Message);
  }
  con.Close();
}
Posted
Updated 21-Oct-11 22:24pm
v3
Comments
Bala Selvanayagam 22-Oct-11 4:48am    
Did you try googling...

Just did a google and this applicable, if yours is access database

http://support.microsoft.com/kb/175168

What is your database ?

1 solution

Try re-writing it so that it uses a Parametrized query instead:
C#
com=con.CreateCommand();
com.CommandText="UPDATE notification SET notice=@NO where id=@ID";
com.Parameters.AddWithValue("@NO", ta1.Value);
com.Parameters.AddWithValue("@ID", va);
This will remove potential problems from your user input (including an SQL Injection attack) and may well cure your problem. And make it easier to read...

If it doesn't, then you need to check that the table name is right, the two column names are right, and the the record exists in the db.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900