建個模塊, Dim varcnn As OleDb.OleDbConnection ReadOnly Property cnn() As OleDb.OleDbConnection
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供德欽網站建設、德欽做網站、德欽網站設計、德欽網站制作等企業(yè)網站建設、網頁設計與制作、德欽企業(yè)網站模板建站服務,十載德欽做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
Get
If varcnn Is Nothing OrElse varcnn.State ConnectionState.Open Then Dim cnstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""" My.Application.Info.DirectoryPath "\Contact.mdb"";Persist Security Info=True"
varcnn = New OleDbConnection(cnstr)
varcnn.Open()
End If
Return varcnn
End Get
登錄窗體,新建一個就行了。代碼Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Using cmd As New OleDb.OleDbCommand("select password from tbuser where userid =?", cnn)
cmd.Parameters.Add("?", OleDbType.VarChar).Value = Me.UsernameTextBox.Text
Dim obj As Object = cmd.ExecuteScalar
If (Not IsDBNull(obj)) AndAlso (obj IsNot Nothing) AndAlso obj = PasswordTextBox.Text Then
Me.DialogResult = Windows.Forms.DialogResult.OK
Else MessageBox.Show("密碼不正確!") Return
End If
End Using Me.Close()
End Sub Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Me.Close()
End SubEnd Class 項目屬性里點查看應用程序事件,寫代碼Namespace My ' 以下事件可用于 MyApplication:
'
' Startup: 應用程序啟動時在創(chuàng)建啟動窗體之前引發(fā)。
' Shutdown: 在關閉所有應用程序窗體后引發(fā)。如果應用程序異常終止,則不會引發(fā)此事件。
' UnhandledException: 在應用程序遇到未處理的異常時引發(fā)。
' StartupNextInstance: 在啟動單實例應用程序且應用程序已處于活動狀態(tài)時引發(fā)。
' NetworkAvailabilityChanged: 在連接或斷開網絡連接時引發(fā)。
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
Dim f As New LoginForm1
If Not f.ShowDialog = DialogResult.OK Then
End
End If
End Sub End ClassEnd Namespace
你測試一下吧。
Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click
If TextBox Text = Or TextBox Text = Then
Label Text = 請確認您的輸入!
Return
End If
Dim sql As String = select * from pwd where stu_id=@stu_id and pwd=@pwd
Dim m As SqlCommand = New SqlCommand(sql conn)
m Parameters Add(New SqlParameter( @stu_id SqlDbType Int ))
m Parameters( @stu_id ) Value = TextBox Text
m Parameters Add(New SqlParameter( @pwd SqlDbType Char ))
m Parameters( @pwd ) Value = TextBox Text
Dim dr As SqlDataReader
conn Open()
dr = m ExecuteReader
If dr Read Then
Session( stu_id ) = TextBox Text
dr Close()
m Cancel()
Dim sql_ As String = update stu_base set point=point+ where stu_id=@stu_id
m = New SqlCommand(sql_ conn)
m Parameters Add(New SqlParameter( @stu_id SqlDbType Int ))
m Parameters( @stu_id ) Value = Session( stu_id )
m ExecuteNonQuery()
m Cancel()
Response Redirect( detail aspx?stu_id= Session( stu_id ) )
Else
Label Text = 您還沒有注冊或賬號密碼錯誤
End If
End Sub
Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click
TextBox Text =
TextBox Text =
lishixinzhi/Article/program/net/201311/13960
創(chuàng)建完相應的用戶名,密碼控件之后,輸入以下代碼:
Imports System.Data.OleDb
Public Class Form1
Private Sub cmdok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdok.Click
Dim m_username As String
Dim m_userpwd As String
Dim cmd_result As MsgBoxResult
Dim m_da As New OleDbDataAdapter
Dim m_ds As New DataSet
Dim m_command As New OleDbCommand
Dim strsql As String
m_username = txtusername.Text
m_userpwd = txtuserpwd.Text
strsql = " select * from user_info where username='" m_username "' and userpwd='" m_userpwd "'"
OleDbConnection1.Open()
m_command.CommandType = CommandType.Text
m_command.CommandText = strsql
m_command.Connection = OleDbConnection1
m_da.SelectCommand = m_command
m_da.Fill(m_ds, "user_info")
If m_ds.Tables("user_info").Rows.Count 0 Then
cmd_result = MsgBox("歡迎登錄", MsgBoxStyle.OKOnly, "提示")
Else
MsgBox("登錄失敗,請確認用戶名和密碼")
End If
End Sub
End Class