Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Why this Exception error is giving.

My CS code is given below

C#
void sub(Object s, EventArgs e)
{
   con.Open();
   com=con.CreateCommand();
   com.CommandText="UPDATE cv SET name = '" + t1.Text.Trim() + "',pass='" + t3.Text.Trim() + "',pdob='" + t5.Text.Trim() + "',mob='" + t6.Text.Trim() + "',psex='" + d1.SelectedItem.Text.Trim() + "',pstatus='" + d2.SelectedItem.Text.Trim() + "',address='" + tax.Value + "',cobj='" + t7.Text.Trim() + "',eque='" + t8.Text.Trim() + "',etype='" + d1.SelectedItem.Text.Trim() + "',eyear='" + t9.Text.Trim() + "',edur='" + t10.Text.Trim() + "',sind='" + d1.SelectedItem.Text.Trim() + "',sjob='" + t11.Text.Trim() + "',scom='" + t12.Text.Trim() + "',sdate='" + t13.Text.Trim() + "',sdur='" + t14.Text.Trim() + "' where email='" + t2.Text.Trim() + "'";
   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 UPDATED sucessfully";
      ph1.Controls.Add(lbl1);
   }
   catch(Exception ex)
   {
      Response.Write(ex.Message);
   }
      con.Close();
   }
Posted
Updated 26-Dec-11 20:29pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Dec-11 3:28am    
What is "exception error", same as "error exception"? :-)
--SA

 
Share this answer
 
Comments
Wendelius 27-Dec-11 2:35am    
Good link, 5.
The first rule of thumb, never concatenate values to an SQL statement. Instead use SqlParameterhttp://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx[^] (if this is SQL Server, otherwise use relevant parameter class like OleDbParameter).

To your question, see: Solving the Operation Must Use An Updateable Query error
[^] or http://support.microsoft.com/kb/175168[^]
 
Share this answer
 
Comments
thatraja 27-Dec-11 2:54am    
5!
Wendelius 27-Dec-11 3:11am    
Thanks :)

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