ADO.NET AddNew EndCurrentEdit & "Column 'Appt_ID' does not allow nulls" SOLVED

T

tony010409020622

I see this question asked in different ways both in this newsgroup and
on bulliten boards, I just stumbled on the fix. What I had was
basically correct, but missing one line. In the Update button, after
this:

Me.BindingContext(DsAppointments1, "Appointments").EndCurrentEdit()

THIS is required to write the data back to the DB:

OleDbDataAdapter1.Update(DsAppointments1)

The .net help implied that EndCurrentEdit() wrote to the DB, and didnt
mention updating the adapter where it should have been mentioned.

I tweaked the code a bit in other areas, the final code I'm using for
the ADD and UPDATE buttons follows:

btnADD_click...

REM move to the last record
Call btnLast_Click(Nothing, Nothing)
REM Access the DataTable object
Dim myTable As DataTable = DsAppointments1.Appointments()
REM confirm properties for Primary Key are properly set
myTable.Columns("Appointment_ID").ReadOnly = False
myTable.Columns("Appointment_ID").AutoIncrement = True
REM Clear the text boxes of their current record data
Me.BindingContext(DsAppointments1, "Appointments").AddNew()

btnUPDATE_click...

REM Tell VB youre done editing

Me.BindingContext(DsAppointments1,"Appointments").EndCurrentEdit()
REM Tell VB to write the data you added to the DB
OleDbDataAdapter1.Update(DsAppointments1)

One FYI: column numbers, such as
myTable.Columns(0).AutoIncrement = True
At least seem less reliable in .net than they were in VB 6
 
I

ijustok

Before EndCurrentEdit, Show field's value

MessageBox(myTable.Columns("Appointment_ID").ToString());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top