skip to Main Content
        TextBox txtStatus = GridView1.Rows[e.RowIndex].FindControl("TextBox6") as TextBox;
        string strcn = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
        SqlConnection con = new SqlConnection( strcn);
        con.Open();
        SqlCommand cmd = new SqlCommand("update Associate_Table set [Status] = @Status where [Associate ID] =+Convert.ToInt32(id.Text)", con);
        cmd.Parameters.AddWithValue("@Status", txtStatus.Text);
        int i = cmd.ExecuteNonQuery();
        
        con.Close();

plz help getting error. I have no idea what, I done here
and the error is System.Data.SqlClient.SqlException: ‘Incorrect syntax near ‘.’.’

2

Answers


  1. Put aout the parameter from the query string…

    Something like :

    SqlCommand cmd 
       = new SqlCommand("update Associate_Table 
                         set [Status] = @Status where [Associate ID] = " 
                        + Convert.ToInt32(id.Text), con);
    
    Login or Signup to reply.
  2. Use the + sign only for concatenating string values. Update your code by following snippet.

    SqlCommand cmd = new SqlCommand("update Associate_Table set [Status] = @Status where [Associate ID] = @AssociateID", con);
    cmd.Parameters.AddWithValue("@Status", txtStatus.Text);
    cmd.Parameters.AddWithValue("@AssociateID", Convert.ToInt32(id.Text));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search