vb连接数据库

前端之家收集整理的这篇文章主要介绍了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 '显示连接的状态 MsgBox "连接成功!",statestring If Trim(Combo1.Text = "") Then MsgBox ("用户名不能为空,请重新输入!") txt2.Text = "" Combo1.SetFocus Else If Trim(txt2.Text = "") Then MsgBox ("密码不能为空,请重新输入!") txt2.Text = "" txt2.SetFocus Else my_recordset.Open "select * from user where id='" & Combo1.Text & "'",cnn If my_recordset.EOF = True Then MsgBox ("用户名不存在!") Combo1.Text = "" txt2.Text = "" Combo1.SetFocus Else If (Trim(txt2.Text) = my_recordset.Fields("passwd")) Then Me.Hide Frm_main.Show 'MsgBox ("登陆成功!") Else MsgBox ("密码错误登录失败!") txt2.Text = "" txt2.SetFocus End If End If End If End If End Sub 原文链接:https://www.f2er.com/vb/259585.html

猜你在找的VB相关文章