我有一个网页表单,其中我使用的是具有多行属性的文本框控件,在此控件下方,我使用的是标签控件。我希望无论我在每个条目后在文本框中输入什么内容,标签控件中的文本都会附加我作为输入提供的文本。 这是我的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异常。请指导我做错的地方?
答案 0 :(得分: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());
}
}