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(DetailsViewMode.Insert)

        End Sub 

When enter data into the fields and click "Insert" it adds a new record with no error.

Now I want put the selected customer id from the Dropdownlist on Default.aspx into the customer filed in the DetailsView on Add.aspx. I add the following code:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

              DetailsView1.ChangeMode(DetailsViewMode.Insert)

              If Not IsPostBack Then

                    Dim ddl As DropDownList                    ddl = CType(PreviousPage.FindControl("DropDownList1"), DropDownList)

                    DetailsView1.Rows(0).Cells(1).Text = ddl.SelectedValue

        End Sub

 It does put the selected customer id into the customer field in the DetailsView, and this field is unabled. When enter data into all other fields and click "Insert", there's an error said:

"Cannot insert the value NULL into column 'customer', table 'DEMO"

But there's the customer id in the field. Why the it's Null when inserting?

Thanks,

 

 

 

 

 

0
yabing
11/12/2008 1:36:06 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1230 Views

Similar Articles

[PageSpeed] 49

Are you using SQLDataSource? If yes, verify that your parameter is set correctly in Inserting event. You can also set your parameter there just in case.


Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
0
Naom
11/12/2008 4:44:05 AM

Yes, use SQL Datasouce:

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

DeleteCommand="DELETE FROM [scheme].[slemail] WHERE [customer] = @customer AND [seq] = @seq"

InsertCommand="INSERT INTO [scheme].[slemail] ([customer],[seq],[ email ],[address]) VALUES (@customer, @seq,@email,@address)" SelectCommand="SELECT * FROM [scheme].[slemail]"

UpdateCommand="UPDATE [scheme].[slemail] SET [ email ]=@email, [address] = @address WHERE [customer] = @customer AND [seq] = @seq"

SelectCommand="SELECT * FROM [scheme].[slemail]" >

 

<DeleteParameters>

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

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

</DeleteParameters>

<UpdateParameters>

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

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

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

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

</UpdateParameters>

<InsertParameters>

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

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

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

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

</InsertParameters>

</asp:SqlDataSource>

Having said that inserting data works when customer field data entered manually. But it doesn't work when setting customer field by coding and the field is unabled automaticlly.

Thanks 

0
yabing
11/13/2008 1:09:16 AM

Hi yabing,

Try to remove PostBack check in Page_Load event, because the cell in DetailsView will lose the text after the postback of clicking insert button.

Thanks,


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Qin
11/14/2008 8:34:10 AM
Reply:

Similar Artilces:

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. INSER...

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...

How to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value')
Hi, I want to INSERT INTO [Table] ([Field]) VALUES('I Have a ' in value') please teach me how to xxx INSERT INTO [Table] ([Field]) VALUES('I Have a '' in value') instead of one single quote, u need to add one more.Om Prakash Use Parameterized Queries ...you woudnt have to worry about escape characters besides saving your db from sqlinjection attacks. hth***********************Dinakar NethiLife is short. Enjoy it.***********************...

'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...

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...

''''''''''''''''''''
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...

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...

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', '...

Error:Column 'FieldName' is constrained to be unique. Value '0' is already present
Hi, Can anyone help me? when I am inserting a record to a dataset I am getting  Column 'FieldID' is constrained to be unique.  Value '0' is already present. I have 2 fields in table like FieldID,FieldName where FieldID id is Primary key and identity column I am not inserting any value to FieldID as it is identity column. DataRow newDR= dbDataSet.Tables[strTable].NewRow();for (int i = 0; i < e.Row.Cells.Count; i++) { if ( e.Row.Cells[i].Key != "FieldID" ) {if (e.Row.Cells[i].Value != null) { newDR[e.Row.Cells[i].Key] = e.Row.Cells[i...

ObjectDataSource 'odsUser' has no values to insert. Check that the 'values' dictionary contains values
Hi All! I am currently trying to pull 2 values from two different sources (Details View & a Session) to use in a Stored Proceedure.  I have spent quite a bit of time trying to determine what is occuring without any luck. However, by the Subject Line you can tell that it's not getting anything for some reason?  Here are the components:Object Datasource:<asp:ObjectDataSource ID="odsUser" runat="server" DataObjectTypeName="System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************]]"DeleteMethod="RemoveEnrollment...

Version 03.01.01 Install Error: Cannot insert the value NULL into column 'RoleId'
I am getting an error during the installation of 03.01.01 shown below on a clean machine.  Do I need to fix before using the portal?  How would I fix? Installing DotNetNuke Version: 03.01.01 Installation Status Report00:00:01.532 - Installing Version: 3.1.000:00:01.532 - Installing Script: DotNetNuke.SetUp.SqlDataProvider00:00:01.592 - Installing Script: DotNetNuke.Schema.SqlDataProvider00:00:10.394 - Installing Script: DotNetNuke.Data.SqlDataProvider00:00:14.090 - Installing MemberRole Provider:00:00:14.100 - Executing InstallCommon.sql00:00:1...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Is having a trigger that inserts a row in Table 'A', when a row in same table is inserted by ADo.Net code?
I want to insert a row for a Global user  in Table 'A' whenever ADO.Net code inserts a Local user row into same table. I recommended using a trigger to implement this functionality, but the DBA was against it, saying that stored proecedures should be used, since triggers are unreliable and slow down the system by placing unecessary locks on the table. Is this true OR the DBA is saying something wrong? My thinking is that Microsoft will never include triggers if they are unreliable and the DBA is just wanting to offload the extra DBA task of triggers to the programmer so that a s...

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 - DetailsView Insert Error: Cannot insert the value NULL into column 'customer', table 'DEMO - asp.net.presentation-controls

Resources last updated: 1/19/2016 7:03:00 AM