
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