2 Replies - 259 Views - Last Post: 07 February 2013 - 02:12 AM Rate Topic: -----

#1 Disaresta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-January 13

what error did i make in this code

Posted 07 February 2013 - 01:45 AM

Imports system.data.odbc
Public Class LoginForm1
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim u As String
        Dim p As String
        Dim user As String = UsernameTextBox.Text
        Dim pass As String = PasswordTextBox.Text
        Dim cnn As New Odbc.OdbcConnection
        Dim cmd As New Odbc.OdbcCommand()
        Dim dr As Odbc.OdbcDataReader
        Try
            cnn.ConnectionString = "Dsn=casestudy"
            cnn.Open()
            cmd = cnn.CreateCommand
            cmd.CommandText = "select password from users where username = ' " & user & "' "
            dr = cmd.ExecuteReader
            While dr.Read
                u = dr.GetString(0)
            End While
 
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & " : " & ex.Message)
        End Try
        If pass = u Then
            Customer.Show()
            Me.Hide()
        End If

    End Sub


using a visual basic 2005, connection is through ODBC,
my database is +----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| UserID | int(6) | NO | PRI | NULL | auto_increment |
| Username | varchar(40) | NO | | NULL | |
| Password | varchar(25) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+

my real problem is that when i typed in my user and password, nothing happens, sometimes is just lags,
I'm new to this, and if ever I miss a detail/s please tell me

Is This A Good Question/Topic? 0
  • +

Replies To: what error did i make in this code

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3320
  • View blog
  • Posts: 11,227
  • Joined: 12-December 12

Re: what error did i make in this code

Posted 07 February 2013 - 02:02 AM

"select password from users where username = ' " & user & "' "

You have quoted an extra space at the beginning of ' user'.

BTW You are retrieving a single value so there is no need for a WHILE loop.
Was This Post Helpful? 0
  • +
  • -

#3 Disaresta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-January 13

Re: what error did i make in this code

Posted 07 February 2013 - 02:12 AM

View Postandrewsw, on 07 February 2013 - 02:02 AM, said:

"select password from users where username = ' " & user & "' "

You have quoted an extra space at the beginning of ' user'.

BTW You are retrieving a single value so there is no need for a WHILE loop.



uhh,... thanks

To be honest, I'm kinda embarassed right now for not seeing that obvious/simple mistake,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1