10 Replies - 575 Views - Last Post: 09 April 2012 - 11:17 AM Rate Topic: -----

#1 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Oledbexception was unhandled

Posted 08 April 2012 - 08:09 AM

this error i got:

Syntax error (missing operator) in query expression 'ID_Number=()'

this is my code:
Private Sub POS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DA2 = New OleDbDataAdapter("SELECT ID_Number,First_Name,Middle_Name,Last_Name,Home_Address,Pwesto from Dealer where ID_Number=(" & POS_inputdealer.tbx_idealer.Text & ")", cn)
        Dim dt2 = New DataTable
        DA2.Fill(dt2)

        lbl_id.Text = (dt2.Rows(0)("ID_Number"))
        lbl_name.Text = (dt2.Rows(0)("First_Name,Middle_Name,Last_Name"))
        lbl_address.Text = (dt2.Rows(0)("Home_Address"))
        lbl_pos.Text = (dt2.Rows(0)("Pwesto"))

End Sub



ID_Number is an autonumber in my database (ms.access2008)
please help

Is This A Good Question/Topic? 0
  • +

Replies To: Oledbexception was unhandled

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Oledbexception was unhandled

Posted 08 April 2012 - 08:14 AM

lose the parans. It should be apostrophes. '" & POS_inputdealer.tbx_idealer.Text & "'
Was This Post Helpful? 0
  • +
  • -

#3 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Re: Oledbexception was unhandled

Posted 08 April 2012 - 08:21 AM

i tried to put that but it gives me another error:

Data type mismatch in criteria expression.
Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Oledbexception was unhandled

Posted 08 April 2012 - 08:24 AM

I suppose ID_Number holds an integer value, right? You need to convert the user input from POS_inputdealer.tbx_idealer.Text to integer as well. Type Conversion Functions
Was This Post Helpful? 0
  • +
  • -

#5 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Re: Oledbexception was unhandled

Posted 08 April 2012 - 08:35 AM

i can't understand im new in VB? what should i convert ?

here my POS_inputdealer

Private Sub getID()

        Dim cmd As New OleDbCommand("SELECT ID_Number from Dealer where ID_Number=(" & tbx_idealer.Text & ")", cn)
        cn.Open()

        Dim sdr As OleDbDataReader = cmd.ExecuteReader()
        If (sdr.Read = True) Then
            MessageBox.Show(" Valid ID Dealer Proceed to Transaction")
            Me.Hide()
            POS.Enabled = True
        Else
            MessageBox.Show("Invalid ID Dealer")
            tbx_idealer.Text = ""
            tbx_idealer.Focus()

        End If
        cn.Close()
    End Sub


Was This Post Helpful? 0
  • +
  • -

#6 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Oledbexception was unhandled

Posted 08 April 2012 - 08:47 AM

You need to convert the input you're getting from POS_inputdealer.tbx_idealer.Text. I assume its a Textbox, right? Even if the user inputs a number there, its still considered as a text string until you convert it to an actual integer value. You need to use the function CInt. Look at the link in my previous post for examples.
Was This Post Helpful? 0
  • +
  • -

#7 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Re: Oledbexception was unhandled

Posted 08 April 2012 - 09:17 AM

i tried it but it gives me an error maybe i put it in a wrong place.

first in POS_input dealer:

 Dim cmd As New OleDbCommand("SELECT ID_Number from Dealer where ID_Number=(" & CInt(tbx_idealer.Text) & ")", cn)




then i also put CInt in the POS form?
Was This Post Helpful? 0
  • +
  • -

#8 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Oledbexception was unhandled

Posted 08 April 2012 - 09:26 AM

what's the error?
Was This Post Helpful? 0
  • +
  • -

#9 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Re: Oledbexception was unhandled

Posted 08 April 2012 - 09:37 AM

Conversion from string "" to type 'Integer' is not valid.\

this is my code:

 Dim DA2 = New OleDbDataAdapter("SELECT ID_Number,First_Name,Middle_Name,Last_Name,Home_Address,Pwesto from Dealer where ID_Number=('" & CInt(POS_inputdealer.tbx_idealer.Text) & "')", cn)


Was This Post Helpful? 0
  • +
  • -

#10 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,434
  • Joined: 25-September 09

Re: Oledbexception was unhandled

Posted 09 April 2012 - 09:02 AM

OK, as nK0de stated lose the parenthesis.

The message is stating the apparently POS_inputdealer.tbx_idealer does not have anything in it. It is a 0 length string and is not valid for casting to an Integer type. Ensure that there is a number entered into it prior to running the corrected query below.

Try this
Dim DA2 = New OleDbDataAdapter("SELECT ID_Number, First_Name, Middle_Name, Last_Name, Home_Address, Pwesto FROM Dealer where ID_Number = " & POS_inputdealer.tbx_idealer.Text, cn)


Now as long as ID_Number is a number in your database and there is a row containing the number you enter, this should work.

This post has been edited by CharlieMay: 09 April 2012 - 09:06 AM

Was This Post Helpful? 0
  • +
  • -

#11 xxrhy  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 51
  • Joined: 08-April 12

Re: Oledbexception was unhandled

Posted 09 April 2012 - 11:17 AM

thanks, finally i got it thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1