Error in Tutorial DetailsView"Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.

Hi,
I am trying to do the insert part of detail's view Tutorial (the last one) and I received this error: "Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.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 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails.
The statement has been terminated.


My code is this one.
Thank's a lot.
Raphael

"<%
@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BackColor="White"

BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="au_id"

DataSourceID="SqlDataSource1" DefaultMode="Insert" GridLines="Horizontal" Height="50px"

Width="125px">

<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />

<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />

<Fields>

<asp:BoundField DataField="au_id" HeaderText="au_id" ReadOnly="True" SortExpression="au_id" />

<asp:BoundField DataField="au_lname" HeaderText="au_lname" SortExpression="au_lname" />

<asp:BoundField DataField="au_fname" HeaderText="au_fname" SortExpression="au_fname" />

<asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />

<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />

<asp:BoundField DataField="city" HeaderText="city" SortExpression="city" />

<asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />

<asp:BoundField DataField="zip" HeaderText="zip" SortExpression="zip" />

<asp:BoundField DataField="contract" HeaderText="contract" SortExpression="contract" />

<asp:CommandField ShowInsertButton="True" />

</Fields>

<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />

<EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />

<AlternatingRowStyle BackColor="#F7F7F7" />

</asp:DetailsView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"

InsertCommand="INSERT INTO dbo.authors(au_id, au_lname, au_fname, phone, city, address, state, zip, contract) VALUES (@au_id, @au_lname, @au_fname, @au_phone, @au_city, @au_address, @au_state, @au_zip, @au_contract)"

SelectCommand="SELECT au_id, au_lname, au_fname, phone, address, city, state, zip, contract FROM dbo.authors WHERE (au_id = @au_id)">

<SelectParameters>

<asp:QueryStringParameter Name="au_id" QueryStringField="ID" Type="String" />

</SelectParameters>

<InsertParameters>

<asp:Parameter Name="au_id" Type=String/>

<asp:Parameter Name="au_lname" Type=String/>

<asp:Parameter Name="au_fname" Type=String/>

<asp:Parameter Name="au_phone" Type=String/>

<asp:Parameter Name="au_city" Type=String/>

<asp:Parameter Name="au_address" Type=String/>

<asp:Parameter Name="au_state" Type=String />

<asp:Parameter Name="au_zip" Type=String />

<asp:Parameter Name="au_contract" Type=String />

</InsertParameters>

</asp:SqlDataSource>

</div>

</form>

</body>

</html>

0
Raphael
5/31/2005 4:56:57 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1245 Views

Similar Articles

[PageSpeed] 47

The contracts column in the Authors table in Pubs database is BIT datatype so it is expecting true or fasle boolean value.  So you have to change your code to reflect that.  Hope this helps.


Kind regards,
Gift Peddie
0
Caddre
5/31/2005 6:14:25 PM
I'm having the same issue.  It's just not grabbing the parameters from the detailsview form and inserting those values into the insert statement.  It has nothing to do with SQL datatypes because when I look at the profiler the SQL statement generated by the SqlDataSource control is trying insert all fields as null...  

exec spAdminMarketers @UserName = NULL, @UserPass = NULL, @NickName = NULL, @FirstName = NULL, @LastName = NULL, @Email = NULL, @Address = NULL, @City = NULL, @State = NULL, @Zip = NULL, @Phone1 = NULL, @Phone2 = NULL, @Fax = NULL, @Comments = NULL


here's my code...

<%@ Page Language="VB" MasterPageFile="~/Common/stdElements.master" %>

 

<script runat="server">

 

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 

    <asp:SqlDataSource ID="sdsMarketer" runat="server"

        ConnectionString="<%$ ConnectionStrings:gcdbReferralProgram %>"

        SelectCommand="spGetMarketerByID"

        SelectCommandType="StoredProcedure"

        UpdateCommand="spAdminMarketers"

        UpdateCommandType="storedprocedure"

        InsertCommand="spAdminMarketers"

        InsertCommandType="storedProcedure"

        DeleteCommand="spAdminMarketers"

        DeleteCommandType="StoredProcedure">

        <SelectParameters>

            <asp:ControlParameter ControlID="gvMarketers" Direction="Input" Type="Int32" Name="MarketerID"/>

        </SelectParameters>

        <InsertParameters>

            <asp:Parameter Direction="Input" Name="UserName" Type="String" Size="20" />

            <asp:Parameter Direction="Input" Name="UserPass" Type="String" Size="20" />

            <asp:Parameter Direction="Input" Name="NickName" Type="String" Size="50" />

            <asp:Parameter Direction="Input" Name="FirstName" Type="String" Size="50" />

            <asp:Parameter Direction="Input" Name="LastName" Type="String" Size="50" />

            <asp:Parameter Direction="Input" Name="Email" Type="String" Size="100" />

            <asp:Parameter Direction="Input" Name="Address" Type="String" Size="100" />

            <asp:Parameter Direction="Input" Name="City" Type="String" Size="100" />

            <asp:Parameter Direction="Input" Name="State" Type="String" Size="2" />

            <asp:Parameter Direction="Input" Name="Zip" Type="String" Size="5" />

            <asp:Parameter Direction="Input" Name="Phone1" Type="String" Size="12" />

            <asp:Parameter Direction="Input" Name="Phone2" Type="String" Size="12" />

            <asp:Parameter Direction="Input" Name="Fax" Type="String" Size="12" />

            <asp:Parameter Direction="Input" Name="Comments" Type="String" Size="1000" />

        </InsertParameters>

    </asp:SqlDataSource>

    <asp:DetailsView ID="dvMarketer" DefaultMode="Insert" AutoGenerateRows="false" AutoGenerateInsertButton="true" runat="server" Height="50px" Width="125px" DataSourceID="sdsMarketer" HeaderText="Marketer Details" HeaderStyle-Font-Size="1.5em" HeaderStyle-Font-Bold="true" >

        <Fields>

            <asp:TemplateField HeaderText="User Name: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtUserName" runat="server" MaxLength="20" Text='<%# Eval("UserName")%>' />

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtUserName" ErrorMessage="Required Field" SetFocusOnError="true" />

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Password: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtPassword" runat="server" MaxLength="20" Text='<%# Eval("UserPass")%>' />

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPassword" ErrorMessage="Required Field" SetFocusOnError="true" />

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Nick Name: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtNickName" runat="server" MaxLength="50" Text='<%# Eval("NickName")%>' />

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtNickName" ErrorMessage="Required Field" SetFocusOnError="true" />

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="First Name: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtFirstName" runat="server" MaxLength="50" Text='<%# Eval("FirstName")%>' />

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtFirstName" ErrorMessage="Required Field" SetFocusOnError="true" />

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Last Name: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtLastName" runat="server" MaxLength="50" Text='<%# Eval("LastName")%>' />

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtLastName" ErrorMessage="Required Field" SetFocusOnError="true" />

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="E-mail: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtEmail" runat="server" MaxLength="100" Text='<%# Eval("Email")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Address: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtAddress" runat="server" Width="200" MaxLength="100" Text='<%# Eval("Address")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="City: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtCity" runat="server" MaxLength="100" Text='<%# Eval("City")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="State: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtState" runat="server" Width="20" MaxLength="2" Text='<%# Eval("State")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Zip: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtZip" runat="server" Width="60" MaxLength="5" Text='<%# Eval("Zip")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Primary Phone: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtPhone1" runat="server" Width="80" MaxLength="12" Text='<%# Eval("Phone1")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Secondary Phone: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtPhone2" runat="server" Width="80" MaxLength="12" Text='<%# Eval("Phone2")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Fax: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtFax" runat="server" Width="80" MaxLength="12" Text='<%# Eval("Fax")%>' />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:TemplateField HeaderText="Comments: " >

                <InsertItemTemplate>

                    <asp:TextBox ID="txtComments" runat="server" Text='<%# Eval("Comments")%>' TextMode="MultiLine" Height="50" Width="400" MaxLength="1000" />

                   

                </InsertItemTemplate>

                <HeaderStyle HorizontalAlign="Right" Wrap="False" />

            </asp:TemplateField>

            <asp:CommandField InsertText="Add" ShowInsertButton="True" ShowCancelButton="False" ButtonType="Button"  />

        </Fields>

        <HeaderStyle BackColor="SteelBlue" Font-Bold="True" Font-Size="1.5em" ForeColor="White" />

    </asp:DetailsView>   

    <br />

    <asp:SqlDataSource ID="sdsMarketers" runat="server"

        ConnectionString="<%$ ConnectionStrings:gcdbReferralProgram %>"

        SelectCommand="spGetMarketers"

        SelectCommandType="storedprocedure">

        <SelectParameters>

            <asp:SessionParameter Direction="Input" Name="UserID" Type="Int32" />

        </SelectParameters>

    </asp:SqlDataSource>

   

    <asp:GridView ID="gvMarketers" runat="server" EmptyDataText="No Marketers Found" DataSourceID="sdsMarketers" Width="100%" DataKeyNames="UserID,MarketerID">

        <EmptyDataRowStyle HorizontalAlign="center" />

    </asp:GridView>

   

</asp:Content>

Thanks in advance,


Rich
http://www.DevAndDesign.com/
0
EdenMachine
10/26/2005 3:07:43 PM
Sorry, mine just needed a "Bind" instead of "Eval" - problem solved!
Rich
http://www.DevAndDesign.com/
0
EdenMachine
10/26/2005 9:23:57 PM
Reply:

Similar Artilces:

getting the error: Cannot insert the value NULL into column 'name', table 'InterGlobe.dbo.IG_Admin'; column does not allow nulls. INSERT fails. The statement has been terminated.
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <script runat="server">   private void CrLogin_Click(object source, EventArgs e) {   try { //Response.Write("hello"); SqlDataSource2.Insert(); // Response.Redirect("logincreated.aspx"); } catch(Exception ex) { Response.Write(ex.Message); }   } </script>       <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">       &nbsp;<a...

DetailsView Insert Error: Cannot insert the value NULL into column 'customer', table 'DEMO
Using VWD Express edition creates a page(Default.aspx) with a Dropdownlist for selecting a customer and a GridView to show the details of the selected customer and to edit and delect a customer's detail. I add a button to link to page Add.aspx for add a new record. I add a DetailsView and the following code so it goes to New record mode when page loads:        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)               DetailsView1.ChangeMode(Det...

The server method 'SaveData' failed with the following error: System.Data.NoNullAllowedException: Column 'COLUMN' does not allow nulls.
Hello all, I am dabbling in client side atlas at the moment, and I'm attempting to use a strongly typed dataset with a dataservice to update and insert items into it.  Editing is working flawlessly.  I made a button that can save the data if it's changed.  My problem is in the insert.  I've been using the 1_ListOfTask.aspx example as my starting point, where I created the following:  function onCreateCourse()    {        // Get each control        var newSID = S...

Cannot insert the value NULL into column 'OrderID' -- BUT IT IS NOT NULL!
I am getting this error: "Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT fails." -- But my value is not null. I did a response.write on it and it show the value. Of course, it would be nice if I could do a breakpoint but that doesn't seem to be working. I'll attach a couple of images below of my code, the error, and the breakpoint error.       Server Error in '/' Application. Cannot insert the value NULL into column 'OrderID', table 'outman.outman.Contact'; column does not allow nulls. INSERT...

Stuck between "Cannot insert the value NULL into column 'ID'" and "Violation of PRIMARY KEY constraint"
Cannot find an answer to this in previous posting, though there are similar topics. My primary key "ID" requires a value (is not nullable), and not explictly providing it with one when I update a new record gives the following error: Cannot insert the value NULL into column 'ID', table 'AdClub.mediaq.News'; column does not allow nulls. INSERT fails. 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: S...

ASA Error -195: Column 'script' in the table 'ml_script' cannot be NULL
Hi, I am using SQL Anywhere/UltraLite 8.0.2.4285 When I try to execute the following script in InteractiveSQL, I get this error message. ASA Error -195: Column 'script' in the table 'ml_script' cannot be NULL Before adding a new table script, I want to first check and see if the script exists, and if it does, delete the script. That's why I used "NULL". call ml_add_table_script ( 'Version1.0', 'PRODUCT', 'download_cursor', NULL ); call ml_add_table_script ( 'Version1.0', 'PRODUCT', '...

'Cannot insert the value NULL into column' error when updating in GridView
now it works but when I click "ok" to update into the db the application answer is: Cannot insert the value NULL into column 'livello', table 'c:\asp.net\app_data\database.mdf.dbo.Utenti; column does not allow null. Update fails. The statement has been terminated. Here the gridview:1 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Width="95%" 2 DataKeyNames="id" AllowSorting="True" AutoGenerateColumns="False" 3 DataSourceID="SqlDataSource1...

How to solve error : Column 'Column' does not belong to table 'Table' ? Code attached
Hello    I have a dataset which is successfully being filled. However whenever i try    to access a givewn row of one of the tables in the dataset i get the error    "Column 'ContactId' does not belong to table 'SalesAgent'"    Except that it does and if i use an ordinal reference i can access the value    of the column. If i print the schema sure enough the column is called    ContactId. I have also noticed that if i hover the cursor over the    contactrow i can ac...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

Sql 2005 Bogus error?!?!?! 'Column does not allow insert of NULLS'...(Duh!)
I have been battling this for 2 days! I could write a book on what does not work. I have even tried entering the data manually through the 'Open Table' SSMS function from the Object Explorer. I only have 5 records in the table. The first 4 I added a week or so ago during dev from the ASP.Net 2.0 (w VB) website that is the front end for this DB. I use a DAL between the site and DB.I added two new fields the other day and everything seemed to work fine. Now I get 'Siteid CANNOT BE NULL'. I abandoned attempts to Insert from the Website. The following was done directly th...

Cannot insert the value NULL into column 'RoleId'
When I try to start the application, I get the following error: Cannot insert the value NULL into column 'RoleId', table 'IssueTrackerStarterKit.dbo.IssueTracker_Users'; column does not allow nulls. INSERT fails. During setup, I chose to use Windows security and I'm connecting to the database with the SQL Server sa account (which I typed in to the connection string in the web.config file). I could not finish the install, however, because I got the error: Could not add ASPNET account to database............................... So I ran the CreateDatabaseObjects.sql script using Qu...

Cannot insert the value NULL into column 'ACategoryID',..
Hi, Here's the full error message: Failed to add this category.Cannot insert the value NULL into column 'ACategoryID', table 'LinkExchanger.dbo.tblArticleCategory'; column does not allow nulls. INSERT fails. The statement has been terminated. The ACategoryID column is the very first column and the primary key. Isn't this supposed to just autoincrement by 1 every time a new column is added?  Why is this trying to put the NULL value there? How is the primary key normally incremented for the new record in the program so the value ACategoryID is known? ...

Cannot insert the value NULL into column 'TabID' ...
Hi everyone, I try to personalize the Rainbow for an Intranet WEB Portal. I change a lot in design and can't install the new versions because that. Everything is going well on my laptop (Win 2003 Server, SQL 2000 SP3). On my company server I have Win 2000 Server, SQL 2000 and when I install a new copy it works. But when I copy the proiect and the database from my laptop I get a permanent error. It seems that one or more parameters don't pass in querystring. The error appear when I want to create a new tab for example and it looks like that: Cannot insert the value NULL into co...

Cannot insert the value NULL into column 'ProjectCreatorId'
Hi, I already install and run Time Starter Kit. In fact i can now login, browse..etc..but when  i try to create a new project it gives e an error. The details below. Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'ProjectCreatorId', table 'E:\APMC_PROJECTS\TIMETRACKER\APP_DATA\TIMETRACKER.MDF.dbo.aspnet_starterkits_Projects'; column does not allow nulls. INSERT fails. The statement has been terminated. The 'aspnet_starterkits_CreateNewProject' procedure attempted to return a status of NULL, which is not allowed. A stat...

Web resources about - Error in Tutorial DetailsView"Cannot insert the value NULL into column 'contract', table 'pubs.dbo.authors'; column does not allow nulls. INSERT fails. - asp.net.presentation-controls

Resources last updated: 12/12/2015 1:40:50 AM