simple log in program with database access

ogimy

Member
Joined
Mar 17, 2010
Messages
9
Programming Experience
Beginner
i have make the simple code log in program with connect database.The below code have something problem.Can someone pro solve the problem.:(


Private Sub btnSignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSignIn.Click
Dim conn As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim command As New OleDb.OleDbCommand

conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Prokiller\My Documents\Visual Studio Projects\in process\New Folder (2)22\username.mdb"

conn.Open()
command.CommandText = "SELECT * FROM [UserName] WHERE TblUserName'" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"
command.Connection = conn

da.SelectCommand = command
da.Fill(ds, "username")

Dim count = ds.Tables(0).Rows.Count

If count > 0 Then
MsgBox("ok")
Form2.Show()
Me.Hide()
Else
MsgBox("invalid")

End If

conn.Close()
End Sub
 
yeah Tom is right, you are missing the = but you have also said the column rather than the table

VB.NET:
command.CommandText = "SELECT * FROM [UserName] WHERE TblUserName'" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"

It should be

VB.NET:
command.CommandText = "SELECT * FROM TblUserName WHERE [UserName] = '" & txtUserName.Text & "' AND Pin= '" & txtPin.Text & "';"

or better still

VB.NET:
command.CommandText = "SELECT * FROMFROM TblUserName WHERE UPPER([UserName]) LIKE '%" & txtUserName.Text.ToUpper & "%' AND UPPER(Pin) LIKE '%" & txtPin.Text.ToUpper & "%';"
 
ogimy said:
easy mistake.very hard to find it.
It's only hard to see because you made it so by complicating the code, parameterize the query:
VB.NET:
.CommandText = "SELECT * FROM TblUserName WHERE [UserName] = @UserName AND Pin= @Pin"
.Parameters.AddWithValue("@UserName", txtUserName.Text)
.Parameters.AddWithValue("@Pin", txtPin.Text)
Other benefits include for example avoiding SQL injection.
Further recommendations: Data Walkthroughs and/or Forms over Data Video Series
 
Back
Top