1
Answer

Cannot insert the value NULL into column 'name'......

I am facing the error:

{"Cannot insert the value NULL into column 'name', table 'C:\\DOCUMENTS AND SETTINGS\\ADMINISTRATOR\\DESKTOP\\ARTICLE 17\\SIMPLE LOGIN PROJECT IN ASP.NET\\APP_DATA\\MYDB.MDF.dbo.myTb'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}

I have following MSSQL server database
*************************************
id                  int                    Unchecked
name           varchar(100)    Unchecked
username    varchar(100)    Unchecked
password    varchar(100)    Unchecked
emailid        varchar(100)    Unchecked


I am following code in Default.aspx page
*******************************************
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:myDbConnectionString1 %>"
                InsertCommand="INSERT INTO myTb(name, username, password, emailid) VALUES (@name, @username, @password, @emailid)" SelectCommand="SELECT myTb.* FROM myTb">
                    <InsertParameters>
                   
                    <asp:FormParameter Name="name" FormField="name" />
                    <asp:FormParameter Name="username" FormField="username" />
                    <asp:FormParameter Name="password" FormField="password" />
                    <asp:FormParameter Name="emailid" FormField="emailid" />
                   
                    </InsertParameters>
                </asp:SqlDataSource>



I have following code in default.aspx.cs page
***************************************
protected void create_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Insert();
    }





Then, why I am facing the error like 'name' can not be null. Is something missing there?
Answers (1)