CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012

    Help with a SELECT statement


    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:

    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)
    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
    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

    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

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.