数据库中也只有一个表book,这个问题困扰我几天了,哪位大虾帮我解决一下
总是显示:未处理的“System.Data.DBConcurrencyException”类型的异常出现在 system.data.dll 中。其他信息: 并发冲突: UpdateCommand 影响 0 个记录
Dim cnn As OleDbConnection
Dim dp As OleDbDataAdapter
Dim ds As DataSet
Dim cnnStr As String
Dim sql, updatesql As String
Dim dr As DataRow
cnnStr = "provider=microsoft.jet.oledb.4.0;data source=book.mdb"
cnn = New OleDbConnection(cnnStr)
cnn.Open()
MsgBox("连接成功")
dp = New OleDbDataAdapter
sql = "select * from book"
dp.SelectCommand = New OleDbCommand(sql, cnn)
updatesql = "update book set writer=@writer,name=@name,press=@press where ID=@ID"
dp.UpdateCommand = New OleDbCommand(updatesql, cnn)
Dim paramID = New OleDbParameter("@ID", OleDbType.VarChar, 50, "ID")
Dim paramName = New OleDbParameter("@name", OleDbType.VarChar, 50, "name")
Dim paramWriter = New OleDbParameter("@writer", OleDbType.VarChar, 50, "writer")
Dim paramPress = New OleDbParameter("@press", OleDbType.VarChar, 50, "press")
dp.UpdateCommand.Parameters.Add(paramID)
dp.UpdateCommand.Parameters.Add(paramName)
dp.UpdateCommand.Parameters.Add(paramWriter)
dp.UpdateCommand.Parameters.Add(paramPress)
paramID.Sourceversion = DataRowVersion.Original
ds = New DataSet
dp.Fill(ds, "book")
dg.DataSource = ds.Tables("book")
dr = ds.Tables("book").Rows(2)
If Not (dr Is Nothing) Then
dr("writer") = txt_writer.Text
Else
MsgBox("无此记录")
End If
dp.Update(ds, "book")
cnn.Close()
MsgBox("成功")