Column does not allow nulls

Discussion in 'Windows 2008/IIS 7 Beta [Closed]' started by omicrondemo, Nov 3, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi,

    This should be straight forward, but I've searched high and low on the net.

    I have a FORM which allows me to INSERT data, SQL Server 2005 backend. I populate the all the mandatory fields.

    But when I click on the Insert button, it won't let me save and says:

    Column 'PERSONAL_ID' does not allow nulls


    I'm using tableadapters, business logic layers etc. and pausing clearly shows that the values from the form are being passed to the procedure that I have created 'AddNewRecord'. And PERSONAL_ID is definitely not NULL!

    It fails on

    Line 971: Me.Rows.Add(row)

    PERSONAL_ID is a primary key which I generate. The pause also shows that for PERSONAL_ID it says ' {'Conversion from type 'DBNull' to type 'String' is not valid.'}

    Function AddNewRecord looks like this:

    <System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, True)> _
    Public Function AddNewRecord(ByVal PERSONAL_ID As String, ByVal SURNAME As String, ByVal CHRISTIAN_NAME As String, ByVal SEX As String, _
    ByVal FAMILY_POSITION As String, ByVal FAMILY_ID As String, ByVal ADDRESS_1 As String, ByVal ADDRESS_2 As String, _
    ByVal ADDRESS_3 As String, ByVal ADDRESS_4 As String, ByVal ADDRESS_5 As String, ByVal ADDRESS_6 As String, ByVal POSTCODE As String, ByVal COUNTRY As String, ByVal ORG_ID As String) As Boolean
    ' create a new details row instance
    Dim details As New smDetails.smTbl_DetailsIDDataTable
    Dim detail As smDetails.smTbl_DetailsIDRow = details.NewsmTbl_DetailsIDRow

    details.AddsmTbl_DetailsIDRow(detail)
    .
    .
    .

    Any pointers in the right direction would be appreciated. I'm not sure if using .NET 3.5 is a factor.

    Thanks in advance

    Tushar
     
  2. ps my formview code is this:

    <InsertItemTemplate>
    PERSONAL_ID:
    <asp:TextBox ID='PERSONAL_IDTextBox' runat='server'
    Text='<%# Bind('PERSONAL_ID') %>' AutoPostBack='True' />

    SURNAME:
    <asp:TextBox ID='SURNAMETextBox' runat='server' Text='<%# Bind('SURNAME') %>'
    AutoPostBack='True' />

    CHRISTIAN_NAME:
    <asp:TextBox ID='CHRISTIAN_NAMETextBox' runat='server'
    Text='<%# Bind('CHRISTIAN_NAME') %>' />

    SEX:
    <asp:TextBox ID='SEXTextBox' runat='server' Text='<%# Bind('SEX') %>' />

    FAMILY_POSITION:
    <asp:TextBox ID='FAMILY_POSITIONTextBox' runat='server'
    Text='<%# Bind('FAMILY_POSITION') %>' />

    FAMILY_ID:
    <asp:TextBox ID='FAMILY_IDTextBox' runat='server'
    Text='<%# Bind('FAMILY_ID') %>' />

    ADDRESS_1:
    <asp:TextBox ID='ADDRESS_1TextBox' runat='server'
    Text='<%# Bind('ADDRESS_1') %>' />

    ADDRESS_2:
    <asp:TextBox ID='ADDRESS_2TextBox' runat='server'
    Text='<%# Bind('ADDRESS_2') %>' />

    ADDRESS_3:
    <asp:TextBox ID='ADDRESS_3TextBox' runat='server'
    Text='<%# Bind('ADDRESS_3') %>' />

    ADDRESS_4:
    <asp:TextBox ID='ADDRESS_4TextBox' runat='server'
    Text='<%# Bind('ADDRESS_4') %>' />

    ADDRESS_5:
    <asp:TextBox ID='ADDRESS_5TextBox' runat='server'
    Text='<%# Bind('ADDRESS_5') %>' />

    ADDRESS_6:
    <asp:TextBox ID='ADDRESS_6TextBox' runat='server'
    Text='<%# Bind('ADDRESS_6') %>' />

    POSTCODE:
    <asp:TextBox ID='POSTCODETextBox' runat='server'
    Text='<%# Bind('POSTCODE') %>' />

    COUNTRY:
    <asp:TextBox ID='COUNTRYTextBox' runat='server' Text='<%# Bind('COUNTRY') %>' />

    ORG_ID:
    <asp:TextBox ID='ORG_IDTextBox' runat='server' Text='<%# Bind('ORG_ID') %>' />

    <asp:LinkButton ID='InsertButton' runat='server' CausesValidation='True'
    CommandName='Insert' Text='Insert' />
    <asp:LinkButton ID='InsertCancelButton' runat='server'
    CausesValidation='False' CommandName='Cancel' Text='Cancel' />
    </InsertItemTemplate>

    /emoticons/rolleyes.gif
     
  3. I've found the solution is to replace

    details.AddsmTbl_DetailsIDRow(detail)

    in Function AddNewRecord in the BLL

    with

    Adapter1.InsertQuery_TAM(PERSONAL_ID, SURNAME, CHRISTIAN_NAME, SEX, _
    FAMILY_POSITION, FAMILY_ID, ADDRESS_1, ADDRESS_2, _
    ADDRESS_3, ADDRESS_4, ADDRESS_5, ADDRESS_6, POSTCODE, COUNTRY, ORG_ID)

    i.e. my user defined insert query.

    For some reason adding a new row directly causes the SELECT routine to run, which expects a value for the PERSONAL_ID (primary key). I'm sure I'll discover why in due course.

    Also the above is not really very clear in the tutorials.

    HTH

    Tushar /emoticons/yeah.gif
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page