Here is a sample code of how to connect to a database
this code is for microsoft access 2003
Imports system.Data.OleDb
Module Module1
Public dbpath As String = Application.StartupPath + "\dbBilling.mdb"
Public cnstring = "Provider = Microsoft.Jet.Oledb.4.0;Data Source =" & dbpath
Public con As New OleDbConnection(cnstring)
End Module
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
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
Subscribe to:
Posts (Atom)