发布网友 发布时间:2024-10-01 20:23
共4个回答
热心网友 时间:2024-10-18 01:37
新建vb工程,然后点击“工程”-->“引用”,在以下两个选项前挑勾:
Microsoft Data Environment Instance 1.0
Microsoft ActiveX Objects 2.5 Library
因为你要用Access数据库,所以需要在工程中添加控件。
建立Access数据库,在这个vb工程文件夹新建一个文件夹,命名为table,然后将这个Access数据库文件放入table文件夹中。
源代码:
Private Con_Access As Connections
Private Sub Form_Load()
Set Con_Access = New Connection
With Con_Access
.Provider = "microsoft.jet.oledb.4.0"
.ConnectionString = App.Path & "\table\ship.mdb"
.Open
End With
End Sub
Private Sub cmdOK_Click()
Dim cmd As New Command
Dim rd As New Recordset
cmd.ActiveConnection = Con_Access
cmd.CommandText = "select username,userpassword from usertable where username='" & Text1.Text & "'"
On Error GoTo db_error
Set rd = cmd.Execute
On Error GoTo 0
If rd.EOF Then
MsgBox "用户名不存在。", vbOKOnly + vbInformation, "错误"
Exit Sub
End If
db_error:
MsgBox Err.Description, vbOKOnly + vbInformation, "错误"
End Sub
Private Sub cmdCancel_Click()
End
End Sub
已经附上截图了,如果还有疑问,发电邮给我rearguard_zero@hotmail.com
热心网友 时间:2024-10-18 01:39
'zong变量请在代码界面开始的通用部分定义!热心网友 时间:2024-10-18 01:36
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=C:\Documents and Settings\Administrator\桌面\DATA.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = "select * from 表1 where 编号=1"
rs.Open strSQL, conn, 3, 3
If rs!用户名 = Text1.Text And rs!密码 = Text2.Text Then
MsgBox "登陆成功"
Else
MsgBox "密码或用户名错误"
End If
End Sub
热心网友 时间:2024-10-18 01:39
这是交互操作做的,我的姐,VB不是纯写代码的(当然完全写代码也许也写的出来,那太麻烦了)