Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2005, 06:23 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Add record form bunkerbang Access VBA 5 September 12th, 2007 12:17 AM
Add record mateenmohd Access 1 October 3rd, 2006 06:53 AM
how to add new record as first record in dataset hunzian78@yahoo.com ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 05:23 AM
Help with Add record topshed Classic ASP Basics 6 February 7th, 2006 02:59 AM
Add New compliling, but not actually adding record Louisa VB.NET 2002/2003 Basics 1 January 12th, 2004 11:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.