CedeeCQ
CedeeCQ

Reputation: 45

SQL command for update in C#

I've been having a lot of trouble with these simple lines of code. I tried fixing it many times, but I don't seem to get it. I hope someone can help me with this.

SqlCommand cmd = new SqlCommand("UPDATE dbo.Status SET Status = "<span class=\"label label-success\">Success</span>" WHERE ActivateMember = " +i + "", 
                                mydatabase.cn);

The problem is I'm unable to execute that SqlCommand in C# but I'm able to execute it as a SQL query.

Right now the error is

Unexpected character '\'

Upvotes: 1

Views: 546

Answers (1)

JayV
JayV

Reputation: 3271

Change to use Parameters, it will save you a lot of trouble.

SqlCommand cmd = new SqlCommand("UPDATE dbo.Status SET Status = @status WHERE ActivateMember = @activateMember",mydatabase.cn);
cmd.Parameters.AddWithValue("status", "<span class=\"label label-success\">Success</span>");
cmd.Parameters.AddWithValue("activateMember", i);

Upvotes: 3

Related Questions