An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.data.dll 
Author Message
 An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.data.dll

I am having the following problem when I try to add new data to the
database:

The database table UserInfo, I have userid, firstname, lastname,
group...and in my vb.net code, I have the following:

Me.BindingContext(Me.Datasetadmineuser2, "UserInfo").AddNew()

but I am always getting the following error:

An unhandled exception of type 'System.Data.NoNullAllowedException'
occurred in system.data.dll

It keeps saying "Additional information: Column 'userid' does not
allow nulls."

First, for debug purpose, I have took the primary key off and allow
all nulls for the columns, but it still gives me this error. Does
anyone can give me a hint why this is happening? And how can I slove
this problem?

Thank you.

Irene



Wed, 21 Sep 2005 09:46:39 GMT  
 An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.data.dll

Quote:

> I am having the following problem when I try to add new data to the
> database:

> The database table UserInfo, I have userid, firstname, lastname,
> group...and in my vb.net code, I have the following:

> Me.BindingContext(Me.Datasetadmineuser2, "UserInfo").AddNew()

> but I am always getting the following error:

> An unhandled exception of type 'System.Data.NoNullAllowedException'
> occurred in system.data.dll

> It keeps saying "Additional information: Column 'userid' does not
> allow nulls."

> First, for debug purpose, I have took the primary key off and allow
> all nulls for the columns, but it still gives me this error. Does
> anyone can give me a hint why this is happening? And how can I slove
> this problem?

> Thank you.

> Irene

I have solve the problem by changing AddNew() to the following
code,(seems AddNew() is only for one record? If you need to add a new
row to the table, you need to initialize a newrow()

The code is sth like this:

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnInsert.Click
        'Add text box values to new row in data set UserInfo table.
        Dim newRow As DataRow = DataSet11.Tables("UserInfo").NewRow()
        newRow("userid") = txtUserid.Text
        newRow("FirstName") = txtFirstName.Text
        newRow("LastName") = txtLastName.Text
        newRow("password") = txtPassWord.Text
        newRow("GroupID") = txtGroup.Text

        DataSet11.Tables("UserInfo").Rows.Add(newRow)

        'Update for insert ADO.NET automatically passes data source
        'identity value to current row for Shippers table in data set.
        SqlDataAdapter1.Update(DataSet11, "UserInfo")

                'Move to last row to show inserted row.
        Me.BindingContext(DataSet11, "UserInfo").Position _
            = Me.BindingContext(DataSet11,
"UserInfo").Position.MaxValue

    End Sub
Hope it can helps the other people who have the same problem.

Irene



Thu, 22 Sep 2005 10:27:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

2. An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

3. An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

4. An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll

5. An unhandled exception of type 'System.InvalidProgramException'

6. An unhandled exception of type 'System.ArithmeticException' - SOLUTION

7. problem of converting C's union type to VB's a data type

8. problem of converting C's union type to VB's a data type

9. Unhandled exception in system.windows.forms.dll (in my main form) - argh

10. Error: An unhandled exception of type...

11. 'System.Data.OleDb.OleDbException'

12. Problem with 'Imports System.Data.Odbc'

 

 
Powered by phpBB® Forum Software