dcsimg
Results 1 to 3 of 3

Thread: sql query not meeting conditions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    sql query not meeting conditions

    The following code is looking for the phone number of contacts in a database when the column "hoohoo" = 15. However it doesnt keep to this condition, but displays all of the numbers. Am i missing a line that tells it to keep to the condition???

    Code:
    Dim SQL As String = "SELECT *, Phone FROM TblContacts WHERE Hoodoo=15" 
            Dim myOleDbCommand As New OleDb.OleDbCommand(SQL, con)
    
            con.Open()
            Dim count As Int32 = Convert.ToInt32(myOleDbCommand.ExecuteScalar())
    
            Using myDataReader As OleDb.OleDbDataReader = myOleDbCommand.ExecuteReader()
                If myDataReader.Read() Then
                    While myDataReader.Read()
                        ' txtPhone.Text = 
                        numbers.Text += myDataReader.Item("Phone").ToString + vbCrLf
                        notfound = 0
    
                    End While

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: sql query not meeting conditions

    Quote Originally Posted by youngnoviceinneedofh View Post
    The following code is looking for the phone number of contacts in a database when the column "hoohoo" = 15. However it doesnt keep to this condition, but displays all of the numbers. Am i missing a line that tells it to keep to the condition???

    Code:
    Dim SQL As String = "SELECT *, Phone FROM TblContacts WHERE Hoodoo=15" 
            Dim myOleDbCommand As New OleDb.OleDbCommand(SQL, con)
    
            con.Open()
            Dim count As Int32 = Convert.ToInt32(myOleDbCommand.ExecuteScalar())
    
            Using myDataReader As OleDb.OleDbDataReader = myOleDbCommand.ExecuteReader()
                If myDataReader.Read() Then
                    While myDataReader.Read()
                        ' txtPhone.Text = 
                        numbers.Text += myDataReader.Item("Phone").ToString + vbCrLf
                        notfound = 0
    
                    End While
    Perhaps that difference in the letters - hoohoo vs. Hodoo
    And, why are you using asterisk (*) in your SQL query?

    If you only need the phone number you just use:
    Code:
    SELECT Phone FROM TblContacts WHERE ...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    Re: sql query not meeting conditions

    My thread was incorret, the code was right. sorry. Yeah i'll try taking the * out, thanks.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width