asp.net '靠近'.'.'的语法不正确,' [重复]

k2arahey  于 2023-03-20  发布在  .NET
关注(0)|答案(2)|浏览(140)

此问题在此处已有答案

Why do we always prefer using parameters in SQL statements?(7个答案)
How to give ADO.NET Parameters(4个答案)
3天前关闭.

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();

请帮助获取错误。我不知道我在这里做了什么,错误是System.Data.SqlClient.SqlException:.“”附近的语法不正确。

uz75evzq

uz75evzq1#

**+**符号仅用于连接字符串值。请按以下代码段更新代码。

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));
cu6pst1q

cu6pst1q2#

从查询字符串中输出参数...
比如:

SqlCommand cmd 
   = new SqlCommand("update Associate_Table 
                     set [Status] = @Status where [Associate ID] = " 
                    + Convert.ToInt32(id.Text), con);

相关问题