Skip to main content
 首页 » 编程设计

具有多个 where 子句和多个 id 字段的 C# Sql Server 更新

2024年02月06日16freeliver54

我在字符串 '' 后得到未闭合的引号。我已经尝试了所有方法,如有任何帮助,我们将不胜感激。

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sipConnectionString"].ConnectionString); 
protected void Button1_Click(object sender, EventArgs e) 
{ 
    conn.Open(); 
    string query = "select dealercode, dropdate, couponno from coupon where dealercode = '" + DEALERCODETextBox.Text + "' and dropdate = '" + DROPDATETextBox.Text + "' and COUPONNO = '" + COUPONCOUNTTextBox.Text +"','"; 
    SqlCommand cm = new SqlCommand(query, conn); 
    cm.Parameters.AddWithValue("@couponcount", COUPONCOUNTTextBox.Text); 
    cm.Parameters.AddWithValue("@totalrev", GRANDTOTALTextBox.Text); 
    cm.ExecuteNonQuery(); 
    conn.Close(); 

请您参考如下方法:

在你的查询字符串的最后

and COUPONNO = '" + COUPONCOUNTTextBox.Text +"','"; 

将 +"','"; 替换为 "'";

注意:您的查询字符串还缺少Parameters