【发布时间】:2011-12-13 21:29:16
【问题描述】:
我正在尝试将名称(字符串)插入测试数据库 (sqlce)。基本上,用户将在文本框(input_box)中输入名称并单击“插入按钮”。单击按钮后,将调用“提交”功能。我希望将文本框中的文本用作 insertcommand 的参数。运行它时我没有收到任何错误。但是当我检查表中的数据时,只插入了“null”。我正在尝试学习asp.net。任何帮助,将不胜感激。谢谢你。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Test run</title></head>
<script language="C#" runat = "server">
void Submit(object o, EventArgs e)
{
SqlDataSource1.Insert();
}
</script>
<body style="height: 395px">
<form id="form1" runat="server">
<asp:TextBox ID="Input_box" runat="server"></asp:TextBox>
<asp:Button ID="Insert_button" runat="server" Text=" Insert Button" OnClick = "Submit"/>
<asp:SqlDataSource
ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO Incident_Table(Assignee) VALUES (@assignee)"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT Assignee FROM Incident_Table">
<InsertParameters>
<asp:FormParameter Name="assignee" FormField ="name"/>
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
【问题讨论】:
标签: asp.net sql-server-ce