Outside Computers

Monday, December 13, 2010

sample Login in VB.net 2008

after a long long time of no post, here is a sample of login program in vb.net

this program have still bugs , and if you found one, post it here. Thanks


Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim ds As DataSet = New DataSet()
        Dim dr As OleDbDataReader
        Dim da As OleDbDataAdapter = New OleDbDataAdapter
        Try
            con.Open()
            Dim dc As OleDbCommand = New OleDbCommand("Select * From UserAccounts ", con) 
            dr = dc.ExecuteReader()
            With dr
                If .HasRows Then
                    While .Read()
                        If (.Item("UserName").ToString = UsernameTextBox.Text) And (.Item("Password").ToString                          = PasswordTextBox.Text) Then
                            Dim a As String = .Item("UserName").ToString
                            Dim a1 As String = .Item("Password").ToString
                            Form1.Show()
                            .Close()
                            Exit While
                        End If
                    End While
                    Dim b As String = .Item("UserName").ToString
                    Dim b1 As String = .Item("Password").ToString
                    MsgBox("Username or Password is Incorrect", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                    UsernameTextBox.Text = ""
                    PasswordTextBox.Text = ""            
                End If
            End With
            con.Close()
        Catch ex As Exception
        End Try
        con.Close()
    End Sub


No comments:

Post a Comment