Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("data source=.;database=MRC_Database;integrated security=true;");
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter();
            string updatestr = " Update User_Account set F_name=" + txtFname + ",L_name='" + txtLname + ", phone_no ='" + txtPhone +
                ",PassUser='" + txtNewPass + ",ReEnter_password='" + txtReEnterPass + ", AlternateEmail ='" + txtAlternateEmail +  
                "' where Email='" + LblEmail + "'";

            SqlCommand com = new SqlCommand(updatestr, con);
            da.UpdateCommand = com;
            com.ExecuteNonQuery();
            con.Close();

        }
Posted
Updated 5-May-13 14:49pm
v2
Comments
[no name] 5-May-13 19:54pm    
Never use string concatenation to construct SQL queries. That is an invitation to SQL injection attacks. If you had used a parameterized query, like you should be using, you would not have had this problem to begin with.
Ian A Davidson 5-May-13 20:52pm    
+5 if I could. If you have time, why not post a solution, or a link to one, explaining how to do it?
TnTinMn 5-May-13 21:50pm    
Since you are receiving the error message "Incorrect syntax near 'System'", I suspect that txtFname, txtLname, etc. are textboxes. The implict conversion that C# does in string concatenation is converting each of those to "System.Windows.Forms.TextBox, Text: ".

Use textboxname.Text to retrieve the Text property. But as others have noted, this is not a good way to develop a query string to start with. Follow their advice.

1 solution

You missed an escape (') after the password and before alternate email.
 
Share this answer
 
v2
Comments
Ian A Davidson 5-May-13 20:52pm    
And now I've formatted it, we can see there is also another single quote missing after Lname, before phone number. +5.
noo_ 6-May-13 11:57am    
can you edit it and write it again after editing ??

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