Cannot add new record
Hi, i am doing a database project that store some information abt the different types of telescopes that are sold in a shop. However, i encounter a problem. Whenever i added and saved a new record, i was prompted with this error msg "An unhandled exception of type 'System.Data.NoNullAllowedException' occured in system.data.dll Additional information:Column 'ItemID' does not allow nulls.
I stored my data in Microsoft Acsess, so i thought that i might have missed something there. But after checking, i found no problem with the database at all including the 'ItemID' portion which is set as the primary key. All fields have been filled up.
Below is the code that i have used
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim dsTemp As New DataSet1
Try
OleDbDataAdapter1.Fill(dsTemp)
DataSet11.Clear()
DataSet11.Merge(dsTemp)
Catch ex As Exception
MsgBox("Error to fill data set")
End Try
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Me.BindingContext(DataSet11, "telescope").EndCurrentEdit()
Me.BindingContext(DataSet11, "telescope").AddNew()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim dsTemp As DataSet1
Me.BindingContext(DataSet11, "telescope").EndCurrentEdit() *<-This is the part where the program got stuck and highlighted in green color.
If DataSet11.HasChanges Then
dsTemp = CType(DataSet11.GetChanges, DataSet1)
OleDbDataAdapter1.Update(dsTemp)
DataSet11.AcceptChanges()
End If
End Sub
The error msg always appears after i clicked the save button. Is this a coding problem or something is wrong with my Access database?
|