大家帮忙看看这段代码该怎么修改。谢谢咯。。
Option Explicit
Dim mrc As Recordset
Dim db As ConnectionPrivate Sub OpenFile(ByVal FileName As String) Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";"End SubPrivate Sub OpenTable(ByVal Sql As String)
Set mrc = New Recordset
mrc.Open Sql, db, adOpenStatic, adLockOptimistic
End SubPrivate Sub Command1_Click() '<-------------这里出错的
OpenFile App.Path & "\testpaper.mdb"
OpenTable "Select username,password from users Where username='" & Text1.Text & "' and password='" & Text2.Text & "'"
If mrc.RecordCount > 0 Then
Dim pName As String
pName = mrc.Fields("username").Value
If Adodc1.Recordset.RecordCount > 0 Then '<---------这里的Adodc1呈灰色状态!
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Fields("username").Value = Adodc1.Recordset.Fields("username").Value & "," & pName
Adodc1.Recordset.Fields("checknum").Value = Adodc1.Recordset.Fields("checknum").Value + 1
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("username").Value = pName
Adodc1.Recordset.Fields("checknum").Value = 1
End If
Adodc1.Recordset.Update
Else
MsgBox "没有此用户或密码错误!"
End IfEnd SubPrivate Sub Command2_Click()
Unload Me
End Sub
Option Explicit
Dim mrc As Recordset
Dim db As ConnectionPrivate Sub OpenFile(ByVal FileName As String) Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";"End SubPrivate Sub OpenTable(ByVal Sql As String)
Set mrc = New Recordset
mrc.Open Sql, db, adOpenStatic, adLockOptimistic
End SubPrivate Sub Command1_Click() '<-------------这里出错的
OpenFile App.Path & "\testpaper.mdb"
OpenTable "Select username,password from users Where username='" & Text1.Text & "' and password='" & Text2.Text & "'"
If mrc.RecordCount > 0 Then
Dim pName As String
pName = mrc.Fields("username").Value
If Adodc1.Recordset.RecordCount > 0 Then '<---------这里的Adodc1呈灰色状态!
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Fields("username").Value = Adodc1.Recordset.Fields("username").Value & "," & pName
Adodc1.Recordset.Fields("checknum").Value = Adodc1.Recordset.Fields("checknum").Value + 1
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("username").Value = pName
Adodc1.Recordset.Fields("checknum").Value = 1
End If
Adodc1.Recordset.Update
Else
MsgBox "没有此用户或密码错误!"
End IfEnd SubPrivate Sub Command2_Click()
Unload Me
End Sub
下面代码提示 键列信息不足或不正确,更新影响到多行!Option Explicit
Dim mrc As Recordset
Dim db As ConnectionPrivate Sub OpenFile(ByVal FileName As String) Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data source=E:\testpaper\DB\testpaper.mdb"End SubPrivate Sub OpenTable(ByVal Sql As String)
Set mrc = New Recordset
mrc.Open Sql, db, adOpenStatic, adLockOptimistic
End SubPrivate Sub Command1_Click()
OpenFile App.Path & "\testpaper.mdb"
OpenTable "Select username,password from users Where username='" & Text1.Text & "' and password='" & Text2.Text & "'"
If mrc.RecordCount > 0 Then
Dim pName As String
pName = mrc.Fields("username").Value
OpenTable "Select username,checknum from testdes"
If mrc.RecordCount > 0 Then
mrc.MoveFirst
mrc.Fields("username").Value = mrc.Fields("username").Value & "," & pName
mrc.Fields("checknum").Value = mrc.Fields("checknum").Value + 1
Else
mrc.AddNew
mrc.Fields("username").Value = pName
mrc.Fields("checknum").Value = 1
End If
mrc.Update
Else
MsgBox "没有此用户或密码错误."
End IfEnd SubPrivate Sub Command2_Click()
Unload Me
End Sub