标题:求助 data 的用法
只看楼主
lanshanlhy
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2006-4-16
结帖率:33.33%
 问题点数:0 回复次数:2 
求助 data 的用法

想做一个进入系统的界面
由用户名+密码
textbox 2个 data 一个 按钮一个

但是不知道怎么连接 到数据库
求救
Dim username, password As String

Private Sub Command1_Click()
On Error Resume Next
Data1.RecordsetType = 0
username = Text1.Text
password = Text2.Text
Data1.DatabaseName = "D:\vb±à³Ì\Êý¾Ý¿âÎļþ\ÃÜÂë.mdb"
Data1.RecordSource = "用户名"
此处好象需要写 些什么 但是我不知道
帮 帮忙啊

If Data1.Recordset.Fields("用户名") = username Then
If Data1.Recordset.Fields("密码") = password Then
Form2.Show
Unload Me
Else
MsgBox "ÃÜÂë´íÎó"
End If
Else
MsgBox "ÎÞ´ËÓû§"
Exit Sub
End If

End Sub

搜索更多相关主题的帖子: data 用法 
2006-04-20 19:50
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 

N久前写的..参考一下...

Option Explicit
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim rs1 As ADODB.Recordset

Private Sub CmdOK_Click()
Dim ConStr As String
If TxtUserName.Text = "" Then
MsgBox "請輸入用戶名!", vbOKOnly + vbExclamation, "登錄"
TxtUserName.SetFocus
Exit Sub
End If
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\StuAcc.Mdb"
cn.Open ConStr
cn.CursorLocation = adUseServer
rs.Open "Select * From User_Property", cn, adOpenKeyset, adLockPessimistic
If rs.RecordCount > 0 Then
If TxtUserName.Text <> "" Then
Set rs1 = New ADODB.Recordset
rs1.Open "Select * From User_Property Where User_Name= '" & TxtUserName.Text & "'", cn, adOpenKeyset, adLockPessimistic
If rs.RecordCount > 0 Then
If TxtPassWord.Text <> "" Then
If rs.Fields("User_Name") = TxtUserName.Text And rs.Fields("User_password") = TxtPassWord.Text And rs.Fields("User_Popedom") = Cbop.Text Then
FrmMain.Show
rs1.Close
Unload Me
Else
If rs1.Fields("User_password") <> TxtPassWord.Text Then
MsgBox "密碼錯誤,請與管理員聯系!", vbCritical + vbOKOnly, "密碼錯誤"
TxtPassWord.SetFocus
TxtPassWord.SelStart = 0
TxtPassWord.SelLength = Len(TxtPassWord.Text)
Exit Sub
Else
If rs1.Fields("User_Popedom") <> Cbop.Text Then
MsgBox "權限錯誤,請與管理員聯系!", vbOKOnly + vbCritical, "權限錯誤"
Cbop.SetFocus
Exit Sub
End If
End If
End If
Else
MsgBox "請輸入密碼!", vbOKOnly, "登錄"
TxtPassWord.SetFocus
Exit Sub
End If
Else
MsgBox "沒有該用戶,請與管理員聯系!", vbOKCancel + vbExclamation, "登錄"
Exit Sub
End If
End If
Else
MsgBox "沒有用戶信息,請確定!", vbExclamation + vbOKCancel, "登錄"
TxtUserName.SetFocus
Exit Sub
End If
rs.Close
End Sub

Private Sub CmdCancle_Click()
Unload Me
End Sub

Private Sub Form_Load()
Move Screen.Width / 2 - Width / 2, Screen.Height / 2 - Height / 2
Cbop.AddItem "管理員"
Cbop.AddItem "普通操作員"
Dim MyConStr As String
Dim UserCount As Integer
Dim Mycn As New ADODB.Connection
Dim Myrs As New ADODB.Recordset
MyConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & App.Path & "\StuAcc.mdb"
Mycn.Open MyConStr
Mycn.CursorLocation = adUseClient
Myrs.Open "Select * From User_Property", Mycn, adOpenKeyset, adLockPessimistic
If Myrs.RecordCount <= 0 Then
UserCount = MsgBox("沒有用戶,請先注冊!", vbYesNo + vbExclamation, "登錄")
If UserCount = vbYes Then FrmAddUser.Show
Myrs.Close
Mycn.Close
Set Myrs = Nothing
Set Mycn = Nothing
Unload Me
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set cn = Nothing
End Sub


我的msn: myfend@
2006-04-20 19:53
lanshanlhy
Rank: 1
等 级:新手上路
帖 子:130
专家分:0
注 册:2006-4-16
得分:0 
非常感谢purana 你的帮助 我就去试试
我想应该可以了

永远以今天为荣!
2006-04-20 20:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-58888-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085639 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved