0

我有一个 Web 表单,其中我使用具有多行属性的文本框控件,在此控件下方我使用标签控件。我希望在每次输入后,无论我在文本框中输入什么,标签控件中的文本都会附加上我作为输入给出的文本。这是我的 aspx 页面-

<table border="1">
    <tr>
        <td>Content:</td>
        <td>
            <asp:TextBox ID="txtdetails" runat="server" TextMode="MultiLine" Height="101px" Width="328px"></asp:TextBox><br />
            <asp:Label ID="lblsource" runat="server" Text=""></asp:Label>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <asp:Button ID="btnsub" runat="server" Text="Submit" onclick="btnsub_Click" />
        </td>
    </tr>
</table>

这是我的cs页面-

protected void btnsub_Click(object sender, EventArgs e)
{
    try
    {
        if (txtdetails.Text != "")
        {
            txtdetails.Text = txtdetails.Text.Replace(System.Environment.NewLine, "<br>");
            maxid = g1.generate_max_reg_id("select max(id) from tbl_content");
            rows = g1.ExecDB("insert into tbl_content values(" + maxid + ",'" + txtdetails.Text.ToString() + string.Format("{0}<strong>MyName</strong>", lblsource.Text)+"')");
            txtdetails.Text = string.Empty;
         }
         if (rows > 0)
         {
             ClientScript.RegisterStartupScript(typeof(Page), "AlertMessage", "alert('Successful!!!');window.location='textare_append.aspx';", true);
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }

我在插入查询中遇到 SQL 异常。请指导我在哪里做错了?

4

1 回答 1

0
protected void btnsub_Click(object sender, EventArgs e)
{
    try
    {
        if (txtdetails.Text != "")
        {
            lblsource.Text=lblsource.Text+ txtdetails.Text;
            txtdetails.Text = txtdetails.Text.Replace(System.Environment.NewLine, "<br>");
            maxid = g1.generate_max_reg_id("select max(id) from tbl_content");
            rows = g1.ExecDB("insert into tbl_content values(" + maxid + ",'" + txtdetails.Text.ToString() + string.Format("{0}<strong>MyName</strong>", lblsource.Text)+"')");
            txtdetails.Text = string.Empty;
         }
         if (rows > 0)
         {
             ClientScript.RegisterStartupScript(typeof(Page), "AlertMessage", "alert('Successful!!!');window.location='textare_append.aspx';", true);
         }
     }
     catch (Exception ex)
     {
         Response.Write(ex.ToString());
     }
 }
于 2014-03-31T13:44:18.680 回答