前端之家收集整理的这篇文章主要介绍了
vb连接数据库,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Sub cmd1_Click() Dim cnn As ADODB.Connection Dim my_recordset As ADODB.Recordset Dim connect_string As String Dim statestring As String Set cnn = New ADODB.Connection Set my_recordset = New ADODB.Recordset '连接Access
数据库 connect_string = "DSN=medic_lib97;UID=;PSW=" cnn.Open connect_string Select Case cnn.State Case adStateClose statestring = "adStateClosed" Case adStateOpen statestring = "adStateOpen" End Select '
显示连接的状态 Msg
Box "连接成功!",statestring If Trim(Combo1.Text = "") Then Msg
Box ("
用户名不能为空,请重新输入!") txt2.Text = "" Combo1.SetFocus Else If Trim(txt2.Text = "") Then Msg
Box ("密码不能为空,请重新输入!") txt2.Text = "" txt2.SetFocus Else my_recordset.Open "select * from user where id='" & Combo1.Text & "'",cnn If my_recordset.EOF = True Then Msg
Box ("
用户名不存在!") Combo1.Text = "" txt2.Text = "" Combo1.SetFocus Else If (Trim(txt2.Text) = my_recordset.Fields("passwd")) Then Me.Hide Frm_main.Show 'Msg
Box ("登陆成功!") Else Msg
Box ("密码
错误,
登录失败!") txt2.Text = "" txt2.SetFocus End If End If End If End If End Sub
原文链接:https://www.f2er.com/vb/259585.html