none
login code in vb.net-probs wid DB access RRS feed

  • Question

  • hi,

     

    m new to vb.net...or rather .net...got a project on hand...i wanted to create a login form for my application..

    its quite easy to create a form in vb.net considering so many form tools...

    what my prob is.....

    i want to verify for d usernames n passwords n report a dialog box sayin "Login succeeded" or "Login failed" and if d login is a success , that is, if the username n pw match then they shud be directed to d next form....

    how do i work wid d database to verify them? wanted help wid queries.....

    also i wanted to create an option for creating new user ids  n PWs n also an option for changing d existing PWs...

     

     

    wat ive dun till now is....

    i ve created a table called "login" in MS Access.....

    it goes like this...

    uid             pw

    admin        stego

     

    i ve created a database connection also...n tested it as well...test connection was successful

     

    i created two variables....one for accepting d userid n d other for accepting d pw...

    now how do i go about creating a command or a query dat matches d database wid inputs??

     

    n how do i then navigate to d next form if d login is a success??

    also can u provide me wid d code for changing d pws?

     

    plzzz help me out...! i m in a great mess!!

    i shall be highly grateful to all those who cud voice their suggestions on my problem!

    waiting......................desperately!

     

    Tuesday, February 12, 2008 1:07 PM

All replies

  • If you want to perform a look-up on that login table you can do something like the following:

     

    Code Snippet

    Dim AccessConn As System.Data.OleDb.OleDbConnection

    Dim AccessCommand As System.Data.OleDb.OleDbCommand

    Dim AccessReader As System.Data.OleDb.OleDbDataReader

     

    Dim ConnectionString As String

    ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

    "Data Source=C:\Test Files\db1.mdb;"

     

    AccessConn = New System.Data.OleDb.OleDbConnection(ConnectionString)

     

    AccessCommand = New System.Data.OleDb.OleDbCommand("SELECT Count(uid) AS UserIDCount FROM(login) WHERE uid=@pUserID AND pwd=@pPassword", AccessConn)

    AccessCommand.CommandType = CommandType.Text

     

    AccessCommand.Parameters.Add("@pUserID", CType(System.Data.OleDb.OleDbType.VarWChar, System.Data.OleDb.OleDbType), 15).Value = UserIDVar

    AccessCommand.Parameters.Add("@pPassword", CType(System.Data.OleDb.OleDbType.VarWChar, System.Data.OleDb.OleDbType), 15).Value = PasswordVar

     

    AccessReader = AccessCommand.ExecuteReader

     

    If AccessReader.Read Then

    If AccessReader.Item("UserIDCount") <> 0 Then

    Console.WriteLine("User ID and Password are valid"

    End If

    End If

     

    AccessConn.Close()

     

     

    Tuesday, February 12, 2008 6:09 PM
  • well this is wat i ve.......

    is it right?

    if i run this....it says....."No value given for one or more required parameters"

    wat dus dat mean?

    and yeah.....m toooooo bad at this....m new to all this stuff...bt ive made this effort....

    plz suggest

     

     

     

     

     

     

    Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=I:\PROJECT\dotNet\login.mdb")

    Dim dr As OleDbDataReader

    Dim username As String

    Dim password As String

    username = TextBox1.Text

    password = TextBox2.Text

    Try

    con.Open()

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT Count(uid) AS UserIDCount FROM login WHERE uid=username AND pwd=password", con)

    cmd.CommandType = CommandType.Text

    cmd.Parameters.Add("username", CType(System.Data.OleDb.OleDbType.VarWChar, System.Data.OleDb.OleDbType), 15).Value = username

    cmd.Parameters.Add("password", CType(System.Data.OleDb.OleDbType.VarWChar, System.Data.OleDb.OleDbType), 15).Value = password

    dr = cmd.ExecuteReader

    If dr.Read Then

    If dr.Item("UserIDCount") <> 0 Then

    MessageBox.Show("login success")

    Else

    MessageBox.Show("login failed")

    End If

    End If

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    Finally

    con.Close()

    End Try

     

    Wednesday, February 13, 2008 12:22 PM
  • and oh yes.....i dint understand d query ther....ive an ostrich's brain wen it cums to DBs......plz dnt mind......

     

    Wednesday, February 13, 2008 12:24 PM