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
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