通过ado的方式进行数据库更新时系统报错
Option ExplicitDim mycn As New ADODB.Connection
Dim myrs As New ADODB.Recordset
Private Sub Command1_Click(Index As Integer)
With myrs
Select Case Index
Case Is = 0
myrs.MoveFirst
Case Is = 1
myrs.MovePrevious
If myrs.BOF = True Then
MsgBox "The record is first!"
myrs.MoveFirst
End If
Case Is = 2
myrs.MoveNext
If myrs.EOF = True Then
MsgBox "The record is last"
myrs.MoveLast
End If
Case Is = 3
myrs.MoveLast
End Select
Call viewdata
Label7.Caption = "total " & myrs.RecordCount & " records .this is " & myrs.AbsolutePosition + 2 & "record"
End With
End Sub
Private Sub Command2_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
myrs.Open "select * from room order by no ", mycn, adOpenKeyset, adLockOptimistic
Call Command1_Click(0)
End Sub
Private Sub Command3_Click()
'myrs.Open "select * from room order by no", mycn, adOpenKeyset, adLockOptimistic
myrs.Fields("no") = Text1.Text
myrs.Fields("style") = Text2.Text
myrs.Fields("stauts") = Text3.Text
myrs.Fields("price") = Text4.Text
myrs.Fields("remark") = Text5.Text
myrs.Fields("dep") = Text6.Text
myrs.Update
myrs.Close
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
mycn.Open "driver={sql server};server=WIN-J8VPCTS806B;uid=sa;pwd=Cash791212@;database=accounting"
End Sub
Sub viewdata()
If myrs.Fields("no") <> "" Then Text1.Text = myrs.Fields("no")
If myrs.Fields("style") <> "" Then Text2.Text = myrs.Fields("style")
If myrs.Fields("stauts") <> "" Then Text3.Text = myrs.Fields("stauts")
If myrs.Fields("price") <> "" Then Text4.Text = myrs.Fields("price")
If myrs.Fields("remark") <> "" Then Text5.Text = myrs.Fields("remark") Else Text5.Text = ""
If myrs.Fields("dep") <> "" Then Text6.Text = myrs.Fields("dep") Else Text6.Text = ""
End Sub
在执行command3时,系统报错
"多步oledb操作产生错误,如果可能,请检查每个oledb状态值,没有工作被完成 数据库 ado update
补充:VB , 网络编程