ASP.NET - "Cannot insert the value NULL into column 'firstName' . . ." when trying to do SQL INSERT
<p>Running .NET Version 4.0, I'm trying to INSERT into a table using the SqlDataSource.Insert() I get "Cannot insert the value NULL into column 'firstName' . . ."</p>

<p>The markup was generated by the sql wizard, except for the "DefaultValue=" which I added just to test.
So with the DefaultValue= in place, the INSERT works, but with this removed I get the error message. The column that SQL server is complaining about is the PK for the table so cannot be nullable, but running the debugger, the field IS populated prior to the call to SqlDataSource.Insert().</p>

<p>Any ideas what I am doing wrong?</p>

<p>Here is the markup :-</p>

<pre><code>&lt;h2&gt;
    &lt;asp:Label ID="PageTitle" runat="server"&gt;&lt;/asp:Label&gt;
    &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="&lt;%$ ConnectionStrings:ApplicationServices %&gt;" 
        DeleteCommand="DELETE FROM [profiles] WHERE [firstName] = @firstName" 
        InsertCommand="INSERT INTO [profiles] ([firstName], [lastName], [dateOfBirth], [email]) VALUES (@firstName, @lastName, @dateOfBirth, @email)"
        SelectCommand="SELECT * FROM [profiles] WHERE ([firstName] = @firstName)" 
        UpdateCommand="UPDATE [profiles] SET [lastName] = @lastName, [dateOfBirth] = @dateOfBirth, [email] = @email WHERE [firstName] = @firstName"&gt;
        &lt;DeleteParameters&gt;
            &lt;asp:Parameter Name="firstName" Type="String" /&gt;
        &lt;/DeleteParameters&gt;
        &lt;InsertParameters&gt;
            &lt;asp:Parameter Name="firstName" Type="String"  DefaultValue="Bri"/&gt;
            &lt;asp:Parameter Name="lastName" Type="String" DefaultValue="Moss"/&gt;
            &lt;asp:Parameter DbType="Date" Name="dateOfBirth"  DefaultValue="13/04/1961"/&gt;
            &lt;asp:Parameter Name="email" Type="String"  DefaultValue="bri@hotmail.com"/&gt;
        &lt;/InsertParameters&gt;
        &lt;SelectParameters&gt;
            &lt;asp:Parameter DefaultValue="Ken" Name="firstName" Type="String" /&gt;
        &lt;/SelectParameters&gt;
        &lt;UpdateParameters&gt;
            &lt;asp:Parameter Name="lastName" Type="String" /&gt;
            &lt;asp:Parameter DbType="Date" Name="dateOfBirth" /&gt;
            &lt;asp:Parameter Name="email" Type="String" /&gt;
            &lt;asp:Parameter Name="firstName" Type="String" /&gt;
        &lt;/UpdateParameters&gt;
    &lt;/asp:SqlDataSource&gt;
&lt;/h2&gt;
</code></pre>

<p>Here is the call to SqlDataSource.Insert() . . . </p>

<pre><code>protected void ProfileSubmit_Click(object sender, EventArgs e)
{
    Page.Validate();
    if (Page.IsValid) 
    {
        SqlDataSource1.Insert();
    }
}
</code></pre>

<p>Here is the error message :-</p>

<pre><code>Server Error in '/' Application.
--------------------------------------------------------------------------------
Cannot insert the value NULL into column 'firstName', table 'C:\USERS\KATHARINA\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\HEALTHTRACK\HEALTHTRACK\APP_DATA\ASPNETDB.MDF.dbo.profiles'; column does not allow nulls. INSERT fails.
The statement has been terminated. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'firstName', table 'C:\USERS\KATHARINA\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\HEALTHTRACK\HEALTHTRACK\APP_DATA\ASPNETDB.MDF.dbo.profiles'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source Error: 
Line 21:             if (Page.IsValid) 
Line 22:             {
Line 23:                 SqlDataSource1.Insert();
Line 24:             }
Line 25:         }
</code></pre>
