最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【VB實例】登錄功能 連接Access/SQL Server數(shù)據(jù)庫 Visual Basic 編程

2023-02-21 00:22 作者:凌霄百科  | 我要投稿


登錄1

Private Sub Command登錄_Click()

If Text密碼 = "" Then

MsgBox "登錄密碼不能為空"

Exit Sub

End If

If Text密碼 = "abc123" Then

? ?MsgBox "登錄成功"

? ?Unload Form登錄1

? ?Form系統(tǒng)主頁1.Show 1

Else

? ?MsgBox "登錄密碼不正確"

End If

End Sub

登錄2

Public login_count As Long


Private Sub Command登錄_Click()

Dim 賬號text As String? '定義變量存儲賬號

Dim 密碼text As String? '定義變量存儲密碼

If Trim(Text賬號) <> "" Then? '輸入賬號不能為空

賬號text = Me.Text賬號? '存儲錄入賬號到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "賬號不能為空!"

Exit Sub

End If

If Trim(Me.Text密碼) <> "" Then? '輸入密碼不能為空

? ? If Len(Trim(Me.Text密碼)) < 6 Then

? ? ? ? MsgBox "密碼長度不能小于6位!"

? ? ? ? Exit Sub

? ? End If

密碼text = Me.Text密碼? '存儲錄入密碼到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "密碼不能為空!"

Exit Sub

End If

'-賬號密碼驗證

Dim login_conn As New ADODB.Connection? '連接到ACCESS數(shù)據(jù)庫

With login_conn? ? ? ? ?'mdb格式連接

? ? .ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_data.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"

? ? .Open

End With

Dim login_rs As New ADODB.Recordset

Dim login_sql As String

login_sql = "select * from 用戶表 where 賬號= '" & Me.Text賬號 & "' and 密碼='" & Me.Text密碼 & "'"? ? ?'查詢用戶表

login_rs.Open login_sql, login_conn, adOpenDynamic, adLockOptimistic

If login_rs.EOF = False Then '循環(huán)表的內(nèi)容

On Error Resume Next

user_name = login_rs.Fields("賬號").Value? ? ? '賬號賦值到公共變量

MsgBox "登錄成功"

Unload Me? '關(guān)閉登錄窗體

Form系統(tǒng)主頁2.Show 1

Else

MsgBox "賬號或密碼錯誤,請重新登錄"

login_count = login_count + 1? ?'登錄錯誤3次,退出

? ? If login_count = 3 Then

? ? ? ? MsgBox "賬號或密碼錯誤達3次"

? ? ? ? Unload Me

? ? End If

End If

login_rs.Close

Set login_rs = Nothing

login_conn.Close

Set login_conn = Nothing

Exit Sub

登錄3

Public login_count As Long

Private Sub Command登錄_Click()

Dim 賬號text As String? '定義變量存儲賬號

Dim 密碼text As String? '定義變量存儲密碼

If Trim(Text賬號) <> "" Then? '輸入賬號不能為空

賬號text = Me.Text賬號? '存儲錄入賬號到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "賬號不能為空!"

Exit Sub

End If

If Trim(Me.Text密碼) <> "" Then? '輸入密碼不能為空

? ? If Len(Trim(Me.Text密碼)) < 6 Then

? ? ? ? MsgBox "密碼長度不能小于6位!"

? ? ? ? Exit Sub

? ? End If

密碼text = Me.Text密碼? '存儲錄入密碼到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "密碼不能為空!"

Exit Sub

End If

'-賬號密碼驗證

Dim login_conn As New ADODB.Connection? '連接到ACCESS數(shù)據(jù)庫

With login_conn? ? ? ? ?'mdb格式連接

? ? .ConnectionString = "Provider = microsoft.jet.oledb.4.0;data source=" & App.Path & "\db_data.mdb;Jet OLEDB:DataBase password=abc123;persist security info=false"

? ? .Open

End With

Dim login_rs As New ADODB.Recordset

Dim login_sql As String

login_sql = "select * from 用戶表 where 賬號= '" & Me.Text賬號 & "'"? ? ?'查詢用戶表

login_rs.Open login_sql, login_conn, adOpenDynamic, adLockOptimistic

If login_rs.EOF = False Then '循環(huán)表的內(nèi)容

On Error Resume Next

? ? If 密碼text = login_rs.Fields("密碼").Value Then

? ? ? ? user_name = login_rs.Fields("賬號").Value? ? ? '賬號賦值到公共變量

? ? ? ? MsgBox "登錄成功"

? ? ? ? Unload Me? '關(guān)閉登錄窗體

? ? ? ? Form系統(tǒng)主頁3.Show 1

? ? Else

? ? ? ? MsgBox "密碼錯誤"

? ? ? ? login_count = login_count + 1? ?'登錄錯誤3次,退出

? ? ? ? If login_count = 3 Then

? ? ? ? ? ? MsgBox "密碼錯誤達3次"

? ? ? ? ? ? Unload Me

? ? ? ? End If

? ? End If

Else

MsgBox "賬號不存在"

End If

login_rs.Close

Set login_rs = Nothing

login_conn.Close

Set login_conn = Nothing

Exit Sub

登錄失敗錯誤:

MsgBox Err.Description

End Sub

登錄4

Private Sub Command登錄_Click()

Dim 賬號text As String? '定義變量存儲賬號

Dim 密碼text As String? '定義變量存儲密碼

If Trim(Text賬號) <> "" Then? '輸入賬號不能為空

賬號text = Me.Text賬號? '存儲錄入賬號到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "賬號不能為空!"

Exit Sub

End If

If Trim(Me.Text密碼) <> "" Then? '輸入密碼不能為空

? ? If Len(Trim(Me.Text密碼)) < 6 Then

? ? ? ? MsgBox "密碼長度不能小于6位!"

? ? ? ? Exit Sub

? ? End If

密碼text = Me.Text密碼? '存儲錄入密碼到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "密碼不能為空!"

Exit Sub

End If

'-賬號密碼驗證

Adodc1.RecordSource = "Select * from 用戶表 Where 賬號='" & 賬號text & "'"? ? '篩選ADO控件記錄

Adodc1.Refresh

If Adodc1.Recordset.RecordCount = 1 Then '


? ? If 密碼text = Adodc1.Recordset.Fields("密碼").Value Then

? ? ? ? user_name = 賬號text? ? ? '賬號賦值到公共變量

? ? ? ? MsgBox "登錄成功"

? ? ? ? Unload Me? '關(guān)閉登錄窗體

? ? ? ? Form系統(tǒng)主頁3.Show 1

? ? Else

? ? ? ? MsgBox "密碼錯誤"

? ? ? ? login_count = login_count + 1? ?'登錄錯誤3次,退出

? ? ? ? If login_count = 3 Then

? ? ? ? ? ? MsgBox "密碼錯誤達3次"

? ? ? ? ? ? Unload Me

? ? ? ? End If

? ? End If

Else

MsgBox "賬號不存在"

End If

Exit Sub

登錄失敗錯誤:

MsgBox Err.Description

End Sub

登錄5

Public login_count As Long

Private Sub Command登錄_Click()

Dim 賬號text As String? '定義變量存儲賬號

Dim 密碼text As String? '定義變量存儲密碼

If Trim(Text賬號) <> "" Then? '輸入賬號不能為空

賬號text = Me.Text賬號? '存儲錄入賬號到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "賬號不能為空!"

Exit Sub

End If

If Trim(Me.Text密碼) <> "" Then? '輸入密碼不能為空

? ? If Len(Trim(Me.Text密碼)) < 6 Then

? ? ? ? MsgBox "密碼長度不能小于6位!"

? ? ? ? Exit Sub

? ? End If

密碼text = Me.Text密碼? '存儲錄入密碼到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "密碼不能為空!"

Exit Sub

End If

'-賬號密碼驗證

Dim login_conn As New ADODB.Connection? '連接到ACCESS數(shù)據(jù)庫

With login_conn? ? ? ? ?'連接

? ? .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=123123;Initial Catalog=test1;Data Source=(local)"

? ? .Open

End With

Dim login_rs As New ADODB.Recordset

Dim login_sql As String

login_sql = "select * from 用戶表 where 賬號= '" & Me.Text賬號 & "' and 密碼='" & Me.Text密碼 & "'"? ? ?'查詢用戶表

login_rs.Open login_sql, login_conn, adOpenDynamic, adLockOptimistic

If login_rs.EOF = False Then '循環(huán)表的內(nèi)容

'On Error Resume Next

user_name = login_rs.Fields("賬號").Value? ? ? '賬號賦值到公共變量

MsgBox "登錄成功"

Unload Me? '關(guān)閉登錄窗體

Form系統(tǒng)主頁3.Show 1

Else

MsgBox "賬號或密碼錯誤,請重新登錄"

login_count = login_count + 1? ?'登錄錯誤3次,退出

? ? If login_count = 3 Then

? ? ? ? MsgBox "賬號或密碼錯誤達3次"

? ? ? ? Unload Me

? ? End If

End If

login_rs.Close

Set login_rs = Nothing

login_conn.Close

Set login_conn = Nothing

Exit Sub

登錄6

Public login_count As Long


Private Sub Command登錄_Click()

Dim 賬號text As String? '定義變量存儲賬號

Dim 密碼text As String? '定義變量存儲密碼

If Trim(Text賬號) <> "" Then? '輸入賬號不能為空

賬號text = Me.Text賬號? '存儲錄入賬號到變量中(可拓展更多判斷,如字符長度等)

Else

MsgBox "賬號不能為空!"

Exit Sub

End If

If Trim(Me.Text密碼) <> "" Then? '輸入密碼不能為空

? ? If Len(Trim(Me.Text密碼)) < 6 Then

? ? ? ? MsgBox "密碼長度不能小于6位!"

? ? ? ? Exit Sub

? ? End If

密碼text = Me.Text密碼? '存儲錄入密碼到變量中

Else

MsgBox "密碼不能為空!"

Exit Sub

End If

'-賬號密碼驗證

Adodc1.RecordSource = "Select * from 用戶表 Where 賬號='" & 賬號text & "'"? ? '篩選ADO控件記錄

Adodc1.Refresh

If Adodc1.Recordset.RecordCount = 1 Then '

'? ? MsgBox 密碼text & Adodc1.Recordset.Fields("密碼").Value

? ? Dim A1 As String

? ? A1 = CStr(Adodc1.Recordset.Fields("密碼").Value)

? ? If 密碼text = Trim(A1) Then

? ? ? ? user_name = 賬號text? ? ?'賬號賦值到公共變量

? ? ? ? MsgBox "登錄成功"

? ? ? ? Unload Me? '關(guān)閉登錄窗體

? ? ? ? Form系統(tǒng)主頁3.Show 1

? ? Else

? ? ? ? MsgBox "密碼錯誤"

? ? ? ? login_count = login_count + 1? ?'登錄錯誤3次,退出

? ? ? ? If login_count = 3 Then

? ? ? ? ? ? MsgBox "密碼錯誤達3次"

? ? ? ? ? ? Unload Me

? ? ? ? End If

? ? End If

Else

MsgBox "賬號不存在"

End If

Exit Sub

登錄失敗錯誤:

MsgBox Err.Description

End Sub

系統(tǒng)主頁

Private Sub Form_Load()

Text賬號.Text = user_name

End Sub

公共變量

Public user_name As String? '記錄登錄賬號


【VB實例】登錄功能 連接Access/SQL Server數(shù)據(jù)庫 Visual Basic 編程的評論 (共 條)

分享到微博請遵守國家法律
辰溪县| 靖宇县| 诏安县| 安仁县| 瑞丽市| 永嘉县| 镇赉县| 胶州市| 东阳市| 左云县| 康马县| 门头沟区| 托里县| 日土县| 中江县| 扶沟县| 河东区| 酒泉市| 濮阳县| 集安市| 许昌市| 松溪县| 屯门区| 黄梅县| 广西| 项城市| 军事| 奉新县| 同德县| 扶沟县| 鄂州市| 宣武区| 龙海市| 安徽省| 开远市| 铁岭县| 汝阳县| 广汉市| 青龙| 卢氏县| 海丰县|