8 Replies - 318 Views - Last Post: 15 October 2013 - 03:58 AM Rate Topic: -----

#1 inverse99  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 40
  • Joined: 07-September 13

login error

Posted 14 October 2013 - 07:33 PM

data mismatch in the experession/..,.,error says

this is my codes
 If Validate_User() Then
            strUser = Trim(Me.txtIDNumber.Text).ToLower
            Dim frm As New main
            Me.Hide()
            frm.ShowDialog()

        Else
            MsgBox("Incorrect IDNumber/Password")
        End If
        me1 = txtIDNumber.Text.ToString
        'txtIDNumber.Text = ""
        txtPassword.Text = ""
    End Sub



   Function Validate_User()
        Dim con As New OleDbConnection
        Dim cmd As New OleDbCommand
        Dim dr As OleDbDataReader
        Dim bValid As Boolean = False

        Try

            con = New OleDbConnection(Get_Constring)
            con.Open()
            cmd.Connection = con
            cmd.CommandType = CommandType.Text
            ' cmd.CommandText = "select ID from students_records where IDNumber = '" & Me.txtIDNumber.Text & "' and MiddleName = '" & Me.txtPassword.Text & "'"
            cmd.CommandText = "select IDNumber from students_records where IDNumber = '" & Me.txtIDNumber.Text & "' and MiddleName = '" & Me.txtPassword.Text & "'"

            dr = cmd.ExecuteReader
            If dr.HasRows Then
                bValid = True
            End If

        Catch ex As Exception
            MsgBox(ErrorToString)
        Finally
            con.Close()
        End Try

        Return bValid
    End Function





This post has been edited by inverse99: 14 October 2013 - 07:40 PM


Is This A Good Question/Topic? 0
  • +

Replies To: login error

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,466
  • Joined: 12-June 08

Re: login error

Posted 14 October 2013 - 10:09 PM

With out knowing where the error is happening I would suggest looking to see if the data type for the column 'IDNumber' is a varchar.. and if not then I would suggest changing

IDNumber = '" & Me.txtIDNumber.Text & "'


to not compare a number to a string.
Was This Post Helpful? 0
  • +
  • -

#3 inverse99  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 40
  • Joined: 07-September 13

Re: login error

Posted 14 October 2013 - 10:47 PM

yes sir it is a number.,.,a primary key.,.,,bcause IDNumber is unique
Was This Post Helpful? 0
  • +
  • -

#4 inverse99  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 40
  • Joined: 07-September 13

Re: login error

Posted 15 October 2013 - 01:48 AM

so what im gonna do ?
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,496
  • Joined: 03-December 12

Re: login error

Posted 15 October 2013 - 02:10 AM

Take modi's advice?
Was This Post Helpful? 0
  • +
  • -

#6 inverse99  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 40
  • Joined: 07-September 13

Re: login error

Posted 15 October 2013 - 02:32 AM

what is his advice?
Was This Post Helpful? 0
  • +
  • -

#7 x-logan  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 81
  • Joined: 18-April 13

Re: login error

Posted 15 October 2013 - 03:35 AM

whenever you have numeric field use

IDNumber = " & Me.txtIDNumber.Text & "


instead of

IDNumber = '" & Me.txtIDNumber.Text & "'


or you can use parameterised query.

Parameterized Query

parameterized query example

This post has been edited by x-logan: 15 October 2013 - 03:41 AM

Was This Post Helpful? 1
  • +
  • -

#8 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 557
  • View blog
  • Posts: 2,496
  • Joined: 03-December 12

Re: login error

Posted 15 October 2013 - 03:50 AM

You cannot compare a string to a number. You could cast it with, cint(txtIDnumber.text) or drop the string literal like x-Logan suggested.

Found here
http://msdn.microsof...y/s2dy91zy.aspx

This post has been edited by astonecipher: 15 October 2013 - 03:55 AM

Was This Post Helpful? 0
  • +
  • -

#9 x-logan  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 81
  • Joined: 18-April 13

Re: login error

Posted 15 October 2013 - 03:58 AM

With option strict on you can work with more accuracy....
But what i suggested will work for sure.....

Best way is to use parameterized query

This post has been edited by x-logan: 15 October 2013 - 04:01 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1