Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#

Hi.

I have written an update statemnt in Asp.net with the code below:

C#
protected void UpdateButton(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = ConfigurationManager.ConnectionStrings["PersonTest"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "UPDATE Person SET (Name=@Name,Family=@Family) where (PersonId=@PersonId)";
            cmd.Parameters.AddWithValue("@Name", textbox1.Text);
            cmd.Parameters.AddWithValue("@Family", TextBox2.Text);
            cmd.Parameters.AddWithValue("@PersonId", txtId.Text);

            cmd.Connection = conn;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }


but after debuging this exception occures :
SqlException was unhandled by user code.
Incorrect syntax near '('.


what is the problem?
Posted
Updated 17-Jul-12 21:19pm
v2
Comments
dimpledevani 18-Jul-12 3:18am    
is ther proper space in between your where clause and parenthesis following it???
mohammad ehsan 18-Jul-12 3:21am    
yes thers is one space between where clause and paranthesis.

Can u remove your commented line and try next time .........

and use this code as like
cmd.CommandText = "UPDATE Person SET Name=@Name,Family=@Family where PersonId=@PersonId ";
 
Share this answer
 
v2
Comments
mohammad ehsan 18-Jul-12 3:37am    
thank you it worked well.
but the inserted statement can not be replaced by the new statement in the sqlserver after i update it ?
uncomment person id cmd.parameters line....
 
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