469,579 Members | 1,064 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

How can I do this?

Ajay Bhalala
119 64KB
I have created the login form in vb.net

In this form there are 2 labels : Username & Password
and 2 Text-boxes for enter the username and password and 1 button "Login"

I have created the ms access database named "Project.mdb" and in this database, I have created 1 table named "UserAccount" and it's fields are "ID", "UserName" & "Password"

I have write the code as following...
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2.  
  3. Public Class Login
  4.  
  5.     Public con As New OleDbConnection("Provider=microsoft.jet.oledb.4.0 ; Data Source=E:\Brinda & Jay\Brinda\02 S.Y\VB.NET\My Project\Project.mdb")
  6.     Public qry As String
  7.     Public dr As OleDbDataReader
  8.  
  9. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         con.Open()
  11.         qry = "select * from UserAccount where UserName like ' " & TextBox1.Text & " ' and Password like ' " & TextBox2.Text & " ' "
  12.         Dim cmd As New OleDbCommand(qry, con)
  13.         cmd.CommandText = qry
  14.         cmd.Connection = con
  15.         dr = cmd.ExecuteReader
  16.         If dr.Read = True Then
  17.             MsgBox("Accessed")
  18.         Else
  19.             MsgBox("Not Accessed")
  20.         End If
  21.         con.Close()
  22.     End Sub
  23. End Class
  24.  
there is no error in this code, but when I run this form and though I enter the right username and password but "Not Accessed" msgbox is displays. I can't understand What changes I have to do in this code?

Which changes I have to do in this code? Please help.
Nov 17 '14 #1

✓ answered by Frinavale

Use the OleDbDataReader.HasRows Property instead of OleDbDataReader.Read Method.

Please also read the documentation about using OleDbCommand.Parameters because it will avoid any SQL insertion attacks.

-Frinny

3 1109
Rabbit
12,516 Expert Mod 8TB
Output the query that it's actually running. You put in extra spaces before and after the username and password.
Nov 17 '14 #2
Frinavale
9,735 Expert Mod 8TB
Use the OleDbDataReader.HasRows Property instead of OleDbDataReader.Read Method.

Please also read the documentation about using OleDbCommand.Parameters because it will avoid any SQL insertion attacks.

-Frinny
Nov 17 '14 #3
Ajay Bhalala
119 64KB
Thank you so much for the help to both Rabbit and Frinavale. I will try it. Ok
Nov 18 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by James | last post: by
5 posts views Thread by Scott D | last post: by
2 posts views Thread by Nick | last post: by
2 posts views Thread by Alexander Ross | last post: by
reply views Thread by Dan Foley | last post: by
5 posts views Thread by Lee Redeem | last post: by
5 posts views Thread by christopher vogt | last post: by
6 posts views Thread by Phil Powell | last post: by
1 post views Thread by Michel | last post: by
11 posts views Thread by Maciej Nadolski | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.