色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

如何用vb做注冊用戶

阮建安2年前34瀏覽0評論

如何用vb做注冊用戶?

VB編寫一個可以注冊帳號的登錄系統步驟:

1)1)首先需要用數據庫軟件(如ACCESS軟件)建立一個數據庫,新建幾個表,用以記錄帳號密碼的表、登錄日志表和其他與此有關的所需要的表等。

2)VB新建數據工程,此時VB6集成調試環境左邊工具箱內已加載了有關數據庫編程必須的控件。

3)然后在FORM1窗體中添加ADO數據控件,右鍵-ADODC1控件屬性頁-使用連接字符串,選生成,在提供者選項中選合適的OLE DB連接數據庫等。在ADODC1控件屬性頁使用連接字符串空白文本窗口中就有一長串字符串,注意該字符串可復制到程序代碼用于編程。

ADODC1控件屬性頁的數據源內有命令文本(SQL)編寫窗口可編寫sql查詢語言。該窗口的SQL語句可復制到程序代碼用于編程。

4)可以將SQL查詢語句賦值給ADO數據控件的RecordSource屬性實現。

5)數據的輸入、修改等可靈活應用文本框或數據表格控件與ADO數據控件通過代碼綁定。

6)想使用ADO數據對象,也可將ADO數據控件所寫的代碼較方便的移植給ADO數據對象。

以下是用ADO數據對象編寫的登錄和注冊的代碼:

1)標準模塊代碼:

Option Explicit Public loginname As String Public cn As New ADODB.Connection '定義數據庫的連接存放數據和代碼 Public rs As New ADODB.Recordset Public sql As String Public Newname As String

2)注冊窗體代碼:

Option Explicit Dim Password As String Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text1 <> "" Then sql = "select * from 用戶管理 where 用戶名='" & Text1.Text & "'" ' and 密碼='" & Text2.Text & "'" cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "datadata.mdb;Persist Security Info=False" cn.Open rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic If rs.EOF = True Then '沒有該用戶名可以注冊 MsgBox "用戶名可以注冊!" rs.Close cn.Close Newname = Text1.Text Text4 = Newname Text2.SetFocus Else MsgBox "該用戶名已經存在,換名注冊!" Text1.Text = "" Text1.SetFocus End If End If Exit Sub finish: MsgBox Err.Description End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text2 <> "" Then Password = Text2.Text Text5 = Password Text3.SetFocus End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text3.Text = Text2.Text Then Command3.Enabled = True Command3.SetFocus ElseIf KeyAscii = 13 And Text3.Text <> Text2.Text Then Text3 = "" Text3.SetFocus End If End Sub Private Sub Command1_Click() Unload Me End Sub Private Sub Command3_Click() sql = "select * from 用戶管理" cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "datadata.mdb;Persist Security Info=False" cn.Open rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic rs.AddNew rs.Fields(0) = Newname rs.Fields(1) = Password rs.Update rs.Close cn.Close Command3.Enabled = False End Sub

3)登錄窗體代碼:

Option Explicit Dim pnum As Integer Private Sub Command1_Click() On Error GoTo finish '防錯代碼,防止意外而導致的退出 sql = "select * from 用戶管理 where 用戶名='" & Text1.Text & "' and 密碼='" & Text2.Text & "'" cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "datadata.mdb;Persist Security Info=False" cn.Open rs.CursorLocation = adUseClient rs.Open sql, cn, adOpenDynamic, adLockOptimistic '以上使用最通用的方法來查詢數據庫中是否有匹配的記錄 If rs.EOF = True Then '如果沒有記錄則說明用戶或密碼為錯誤的 If pnum < 2 Then 'pnum就是密碼驗證次數,當次數超過3次,系統會自動保護退出 pnum = pnum + 1 MsgBox "用戶名或密碼錯誤!", vbInformation, "錯誤次數:" & pnum rs.Close cn.Close Text1.Text = "" Text2.Text = "" Text1.SetFocus Exit Sub Else MsgBox "用戶名或密碼錯誤超過三次,系統會自動退出", vbInformation, "提示" End End If Else loginname = rs.Fields(0) Form1.Show rs.Close cn.Close End If Exit Sub finish: MsgBox Err.Description rs.Close cn.Close End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then '獲取按鍵,如果是回車就運行image_click按鈕的內容 Call Command1_Click End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.SetFocus End If End Sub Private Sub Command2_Click() End End Sub Private Sub Command3_Click() frmZhuce.Show End Sub