I am getting this exception and can not figure out why: Cannot insert the value NULL into column 'UserId'
This is my code:
<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>
This is what I have in my code behind file:
public void button1_Click(object sender, System.EventArgs e)
{
InsertText.Insert();
}
INSERT
, you want toUPDATE
. And in that case, you need to know what theUserId
of the record you want to update is, and pass that back. – Icken