Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Solution for update is given below but Syntax error is given in Update Statement.
Please suggest me.

Table name is notification and its field is not declared as text and ntext declared as memo

C#
void update(Object sender, EventArgs e)
{
con.Open();
string va=d1.SelectedItem.Value;
//ta1.Value=va;
 
com=con.CreateCommand();
com.CommandText="UPDATE notification SET ntext = '" + ta1.Value.Replace("\'","\'\'") + "' where nid='" + 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 14-Oct-11 22:33pm
v2
Comments
hitech_s 15-Oct-11 4:33am    
can u post the error what you got

1 solution

There are a couple of things here:
The first thing you need to do is put a breakpoint on the try statement, and examine your com.CommandText to check exactly what is being sent to the SQL server. Without knowing the content of ta1 and va you are just guessing at this stage.

The other is that you really shouldn't do that at all - use Parametrized queries instead because if you don't you are leaving yourself open to accidental or deliberate SQL Inject attacks, which could damage or destroy you database.

C#
com.CommandText="UPDATE notification SET ntext = @NT where nid=@NI";
com.Parameters.AddWithValue("@NT", ta1.Value.Replace("\'","\'\'"));
com.Parameters.AddWithValue("@NI", va);
You may well find that you original problem disappears at the same time...
 
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