troubleshooting Question

Access autonumber field problem

Avatar of Moe DeShong
Moe DeShongFlag for United States of America asked on
Visual Basic.NET
2 Comments1 Solution353 ViewsLast Modified:
I am trying to add a row to a datatable then retrieve the autonumber value.  I use this code to add the row to the datatable

Dim NewRow As DataRow = dtItems.NewRow
         ItemAdapter.InsertCommand = New OleDbCommand("INSERT INTO Items (txtItemNumber, txtItemtype) Values(?, '" & Me.cboItemType.Text & "')", cnnData)
         ItemAdapter.InsertCommand.CommandType = CommandType.Text
         ItemAdapter.InsertCommand.Parameters.Add("@txtItemNumber", OleDbType.Char, 15, "txtItemNumber")
         dtItems.Rows.Add(NewRow)

         AddHandler ItemAdapter.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
         dtItems.Rows.Add(NewRow)
         Try
            ItemAdapter.Update(dtItems)
         Catch ex As Exception
            MsgBox("Update failed")
         End Try
When I get to the dtItems.rows.add(NewRow) I get an error message the the field "txtItemNumber" does not allow DBNull.  Thats obvious because its the autonumber field.  What am I doing wrong.
ASKER CERTIFIED SOLUTION
maidinhtai

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros