Home > Software engineering >  OleDbConnection, delete data can't be successful?
OleDbConnection, delete data can't be successful?

Time:09-16

Dim conn=New OleDbConnection (" PROVIDER=MICROSOFT. JET. The OLEDB. 4.0; DATA SOURCE=g: \ aa MDB ")
Dim da=New OleDbDataAdapter (" Select * From bz ", conn.)

Dim ds=New DataSet ()
Da. The Fill (ds, "student")
Ds. Tables (" student "). The Rows (0). The Delete () 'to Delete the first line
Ds. The AcceptChanges ()

Dim cb As OleDbCommandBuilder=New OleDbCommandBuilder (da)
Da. Update (ds, "student")

Ds=New DataSet ()
Da. The Fill (ds, "student")


Why the code above is not an error, but also does not have to delete the first row in the database, the database has a primary key, insert a row, modify a row perform da. Update command is successful, just delete a row cannot be successful, or an error, why? I am using vb2015,

CodePudding user response:


Dim conn=New OleDbConnection (" PROVIDER=MICROSOFT. JET. The OLEDB. 4.0; DATA SOURCE=g: \ aa MDB ")
Dim da=New OleDbDataAdapter (" Select * From bz ", conn.)
Dim ds=New DataSet ()
Da. The Fill (ds, "student")

'add a record
Dim the Dr As DataRow=ds. The Tables (" student "). The NewRow
'Dr (" Userid ")' primary keys
Dr (" UserPwd ")=8888.888
Dr (" UserName ")="zhang SAN"
Ds. Tables (" student "). The Rows. The Add (Dr)

Dim SCB As OleDbCommandBuilder=New OleDbCommandBuilder (da)
Da. Update (ds, "student") 'database successfully add a record
Conn. Close ()

CodePudding user response:


Dim conn=New OleDbConnection (" PROVIDER=MICROSOFT. JET. The OLEDB. 4.0; DATA SOURCE=g: \ aa MDB ")
Dim da=New OleDbDataAdapter (" Select * From bz ", conn.)
Dim ds=New DataSet ()
Da. The Fill (ds, "student")

Ds. Tables (" student "). The Rows (0) (1)="double liao"
Ds. Tables (" student "). The Rows (1) (1)="hainan"

Dim cb As OleDbCommandBuilder=New OleDbCommandBuilder (da)
Da. Update (ds, "student") 'can successfully modify the data

Ds=New DataSet ()
Da. The Fill (ds, "student")
  • Related