声波遇到障碍物会:vb初学者问题(能用的话我追加50分)

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/27 14:04:26
请问如何用vb连接我自己网站的数据库access
并读取和修改数据信息?

Dim rs As New ADODB.Recordset
dim cnn As New ADODB.Connection

Private Sub Command1_Click()
Dim strsql As String
Set rs = Nothing
Set cnn = Nothing
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\用户表.mdb;Persist Security Info=False"
cnn.Open

If Text1.Text = "" Then
MsgBox "请输入用户名!", vbCritical + vbOKOnly, "提示"
Text1.SetFocus
End If
strsql = "select*from users where username='" & Trim(Text1.Text) & "'"
rs.CursorLocation = adUseClient
rs.Open strsql, cnn, adOpenStatic, adLockOptimistic
If Text2.Text = rs.Fields("password") Then
MDIForm1.Show
Unload Me
Else
MsgBox ("用户名或者密码不正确!"), vbCritical + vbOKOnly, "提示"
If rs.EOF = True Then MsgBox "无此用户", vbCritical + vbOKOnly, "提示" txt_UserName.SetFocus
End If
End Sub