Dim A As String
A = App.Path + "\ACCESS文件.mdb"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & A & ";Persist Security Info=False"
Adodc1.RecordSource = "SELECT * FROM 用戶表 WHERE 用戶名='" + 用戶名 + "' AND 密碼='" + 密碼 + "'"
Adodc1.Refresh
If OT Adodc1.Recordset.EOF Then
主切面.Show
Me.Hide
Else
MsgBox ("用戶名或密碼錯誤!請重新輸入!")
Me.用戶名 = ""
Me.密碼 = ""
'清空文本框內容
End If
End Sub
' 上面是登陸,把ACCESS建立在VB工程壹個文件夾裏取相對的路徑
下面是註冊用戶表:
Private Sub Command2_Click()
Dim A As String
A = App.Path + "\ACCESS文件.mdb"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & A & ";Persist Security Info=False"
Adodc1.RecordSource = "SELECT * FROM 用戶表 "
Adodc1.Refresh
If OT Adodc1.Recordset.EOF Then
Adodc1.recordset.AddNew
Adodc1.recordset.fields("用戶名")=文本框1
Adodc1.recordset.fields("密碼")=文本框2
.....................
Adodc1.recordset.update
文本框1=""
文本框2=""
......
文本框1.setfocus
ELSE
文本框1=""
文本框2=""
.....
文本框1.setfoucus
end if
end sub