Help with a SELECT statement
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help with a SELECT statement

  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Help with a SELECT statement

    Hello,

    I'm trying to make a login system on visual basic. I need it to be able to connect to an access database to find the usernames and passwords. I have coded it as follows:

    Code:
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    
    'Purpose: Make a Connection to the database and fill a Dataset with the Account and AccountTrans records
    'Create a memory cell to store the drive letter of the USB drive
    Dim DriveLetter As Char
    'Get the first charatcer, i.e. the drive letter from the application's StartupPath
    DriveLetter = Application.StartupPath.Substring(0, 1)
    Dim con As New OleDbConnection("Provider=Microsoft.ACE. Source=" & DriveLetter & ":\greenparkschool\AccessPoints.accdb")
    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Account WHERE cusername = '" & txtUsername.Text & "'" And cpassword = '" & txtCpassword.Text & "' ", con)
    con.Open()
    Dim sdr As OleDbDataReader = cmd.ExecuteReader()
    'If the record can be queried, Pass verification and open another form.
    If (sdr.Read() = True) Then
    MessageBox.Show("The user is valid!")
    Dim transaction As New transaction
    transaction.Show()
    Me.Hide()
    Else
    MessageBox.Show("Invalid username or password!")
    End If
    End Sub
    The problem with this is that it says in the error log that an expression is expected and 'cmd' is not declared. The last section of the SELECT statement seems to comment itself out. What can I do to fix this?

    Thanks in advance.

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: Help with a SELECT statement

    The first thing that comes to my mind is that you are in the wrong forum. Everything looks like it was VB.NET what you are using. So maybe you better post there?

  3. #3
    Join Date
    Apr 2012
    Posts
    4

    Re: Help with a SELECT statement

    Oh Ok, sorry about that, ill take it there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center