两个文本框,一个确定按扭.后台有一个用ACCESS建的叫info.mdb的数据库,包括一张用户资料表,两个字段,用户名,密码,假定有一条记录,用户名:lewi,密码:111
现要求在第一个文本匡里写lewi,点确定,密码111出现在第二个文本匡.
要求:不能用控件,用记录集,连接集之类通过编程实现,通过ADO方式访问ODBC实现.
假定目录如下:d/info.mdb
我照他们回的帖子连了,可还是不行,连不上数据库
麻烦高手给一个从头到尾的程序,谢谢你!
现要求在第一个文本匡里写lewi,点确定,密码111出现在第二个文本匡.
要求:不能用控件,用记录集,连接集之类通过编程实现,通过ADO方式访问ODBC实现.
假定目录如下:d/info.mdb
我照他们回的帖子连了,可还是不行,连不上数据库
麻烦高手给一个从头到尾的程序,谢谢你!
Public myword As ADODB.Recordset
Public zt As String
Sub main()
Set cnn2 = New ADODB.Connection
cnn2.ConnectionString = "driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=" & App.Path & "\word.mdb"
cnn2.ConnectionTimeout = 30
cnn2.CursorLocation = adUseClient
cnn2.Open
'cnn.Close wordwendang
Form1.Show
End Sub
上述在模块中
这个再窗提中
xw = "select * from czy where 姓名='" & Trim(Combo1.Text) & "'" '*************
Dim log As ADODB.Recordset
Set log = New ADODB.Recordset
log.Open xw, cnn2, adOpenDynamic, adLockPessimistic
PassWord = Trim(log!密码) '****************8
If log.RecordCount < 1 Then
MsgBox "非法用户!", vbInformation + vbOKOnly, "系统提示"
Combo1.SetFocus
If cs >= 3 Then Unload Me
Exit Sub
End If '**************
'**************log.Close
Set log = Nothing
kl = txtPassword.TextIf kl = PassWord Then
OK = True
Me.Hide
Else
MsgBox "密码错误,再试一次!", vbInformation + vbOKOnly, "系统提示"
txtPassword.SetFocus
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
If cs >= 3 Then Unload Me
End If
End Sub
注意引用工程中的引用microsoft activex data object2.0 library
部件中的 microsoft ado data control6.0(oledb)
name1=trim(text1.text)
if name1<>"" then
check(name1) '调用检查该用户是否存在
else
msgbox "对不起输入信息不能为空!",vbokonly+vbinformation,"系统信息"
end if
end sub
'******************************************
'check(value)函数:
'功能:检查用户是否存在如果存在的话将数据库中的密码赋予文本框2中!
'******************************************
public function check(value)
set cn=createobject("adodb.connection")
cn.open "provider=microsoft.jet.oledb.4.0;data source="& app.path+"\info.mdb"
set fs=createobject("adodb.recordset")
sql="select * from 用户名='"& value & "'"
fs.open sql,cn,1,1
if fs.eof then msgbox " 对不起请输入密码!",vbokonly+vbinformation,"错误"
text2.setfocus
exit sub
end if
text2.text=fs("密码")
end function
Dim adoCnn As New ADODB.Connection
Dim adoCmm As New ADODB.Command
Dim Rs As New ADODB.Recordset
adoCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\info.MDB;Persist Security Info=False"
Rs.CursorLocation = adUseClient
strsql = "select * from employees where name='" & Trim(Text1.Text) & "' "
Rs.Open strsql, adoCnn, adOpenDynamic, adLockBatchOptimistic
If Rs.RecordCount > 0 Then
Text2.Text = Rs.Fields("password")
MsgBox ("欢迎进入XX系统!")
Else
MsgBox ("用户名或密码错误")
End If
End Sub
“工程”-->“引用”-->“Microsoft AxtiveX Data Objects 2.X Library”
注:2.X为版本号,如果你机子上有高版本的就用高版本的,如:2.5或2.6的Private Sub ComOK_Click()'确定按钮事件
Dim SQLstr As String,cnstr AS String
Dim cn AS New ADODB.Connection'连接对象
Dim rs As New ADODB.Recordset'记录集对象
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source= d:\info.mdb;" _
& "Persist Security Info=False" '连接字符串
cn.open' 打开数据库连接
sqlstr="slect * from userinfo where 用户名='" & trim(text1.text) & "'"'SQL语句
rs.open sqlstr,cn,3,3'执行SQL语句,并返回满足条件的记录
text2.text=rs!密码'取出密码字段的数据显示到text2中
rs.close'关闭记录集对象
set rs=nothing
End Sub