提供两种方法参考:
Dim mConn As New ADODB.Connection
Dim mRst As New ADODB.Recordset 'Recordset 对象
Dim mSql As String
Private Sub Command_登陆_Click(Index As Integer)
'查询yhmm=Text1的记录
mSql = "select * from admin where yhmm='" & Text1 & "'"
mRst.Open mSql, mConn, adOpenKeyset, adLockOptimistic
If mRst.RecordCount > 0 Then
'方法1:更新写入数据库
mSql = "UPDATE admin set dlsj='" & Now & "',tlcs=tlcs+1 where yhmm='" & Text1 & "'"
mConn.Execute (mSql)
'方法2:更新写入数据库
'
mRst.Fields("dlsj") = Now '刷新登陆时间
'
mRst.Fields("tlcs") = mRst.Fields("tlcs") + 1 '刷新登录次数
'
mRst.Update
MsgBox "登录成功,密码" & mRst.Fields("yhmm") & "已登录" & mRst.Fields("tlcs") & "次,本次登录时间为" & mRst.Fields("dlsj")
Else
MsgBox "用户名或密码错误,请重新登录"
End If
mRst.Close
End Sub
Private Sub Command_取消_Click(Index As Integer)
Form2.Show
End Sub
Private Sub Form_Load()
'打开数据库
'Set mConn = CreateObject("ADODB.Connection")
mConn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Landed.mdb"
mConn.Open
'打开数据记录
mSql = "SELECT * FROM admin"
mRst.Open mSql, mConn, adOpenKeyset
'将记录加入Combo1(0)
Do While Not mRst.EOF And Not mRst.BOF
If IsNull(mRst.Fields("yhmm")) Then Exit Do
Combo1(0).AddItem mRst.Fields("yhmm")
mRst.MoveNext
Loop
mRst.Close
End Sub