我收到此异常,但无法弄清楚原因:Cannot insert the value NULL into column 'UserId'
这是我的代码:
<asp:TextBox ID="FirstNameBox" runat="server" />
<br />
<br />
<asp:TextBox ID="LastNameBox" runat="server" />
<asp:SqlDataSource
ID="InsertText"
runat="server"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
InsertCommand="INSERT INTO UserForm (UserId,FirstName,LastName) VALUES (@UserId,@FiName,@LaName)">
<InsertParameters>
<asp:ControlParameter Name="FiName" ControlID="FirstNameBox" PropertyName="Text" />
<asp:ControlParameter Name="LaName" ControlID="LastNameBox" PropertyName="Text" />
<asp:Parameter Name="UserId" />
</InsertParameters>
</asp:SqlDataSource>
这就是我的代码隐藏文件中的内容:
public void button1_Click(object sender, System.EventArgs e)
{
InsertText.Insert();
}