0

以下是我的代码。我在我的网站中使用了类。但是我收到错误,因为“',' 附近的语法不正确”......谁能告诉我代码中有什么问题..

protected void btnadd_Click(object sender, EventArgs e)
    {
        s1 = "Update tckt_tbl Set class='" + ddlclass.Text + "',dist=" + lbldist.Text + ",no_of_adults=" + ddladults.Text + ",no_of_senior=" + ddlsenior.Text + ",n1='" + txtn1.Text + "',";
        s1 += "n2='" + txtn2.Text + "',n3='" + txtn3.Text + "',n4='" + txtn4.Text + "',n5='" + txtn5.Text + "',n6='" + txtn6.Text + "',";
        s1 += "ag1=" + txtag1.Text + ",ag2=" + txtag2.Text + ",ag3=" + txtag3.Text + ",ag4=" + txtag4.Text + ",ag5=" + txtag5.Text + ",ag6=" + txtag6.Text + ",";
        s1 += "gen1='" + txtgen1.Text + "',gen2='" + txtgen2.Text + "',gen3='" + txtgen3.Text + "',gen4='" + txtgen4.Text + "',gen5='" + txtgen5.Text + "',gen6='" + txtgen6.Text + "',";
        s1 += "cn1='" + txtchn1.Text + "',cn2='" + txtchn2.Text + "',cag1=" + txtcag1.Text + ",cag2=" + txtcag2.Text + ",cgen1='" + txtcgen1.Text + "',cgen2='" + txtcgen2.Text + "' Where userid=" + Session["suser"].ToString() + "";
        con.ExecQuery(s1);
        Response.Redirect("tcktbook_itckt.aspx");
    }
4

3 回答 3

0

第三行有问题。

s1 += "ag1=" + txtag1.Text + ",ag2=" + txtag2.Text + ",ag3=" + txtag3.Text + ",ag4=" + txtag4.Text + ",ag5=" + txtag5.Text + ",ag6=" + txtag6.Text + ",";

我认为这里没有正确给出逗号和分号。

于 2013-03-21T05:36:59.767 回答
0

我建议您使用参数查询,而不是连接所有内容。但在那之前,你确定你已经付出了所有的价值吗?因为如果您没有为数字字段提供任何值,它应该会显示错误,因为查询变为:

..cag1=,cag2..
于 2013-03-21T07:06:39.950 回答
0

首先,从用户输入构建查询是一个非常糟糕的主意。我建议您改用参数化查询

尝试输出s1以查看查询的样子。

很有可能您的报价不平衡。

于 2013-03-21T05:35:55.457 回答