query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • enrico via DotNetMonster.com

    #1

    query

    Dim sSql As String = " SELECT tbltrcclient.Cl ientID, tbltrcclient.La stname,
    tbltrcclient.Fi rstname, tbltrcclient.Ba rangay, tbltrcclient.Ty peofSeed,
    tbltrcclient.Ty peofArea, tbltrcclient.He ctares FROM tbltrcclient WHERE
    tbltrcclient.Fi rstname <' '
    AND tbltrcclient.La stname LIKE " & Quote(TextBox2. Text) _
    OR tbltrcclient.Fi rstname LIKE " & Quote(TextBox3. Text) _
    OR tbltrcclient.Ba rangay = " & Quote(ComboBox6 .Text) _
    OR tbltrcclient.Ty peofSeed = " & Quote(ComboBox1 .Text)

    If (ComboBox3.Text <" ") Then
    sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox3 .Text)
    End If
    If (ComboBox2.Text <" ") Then
    sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox2 .Text)
    End If

    myd = .runQuery(sSql)

    this is my search query where a user can search whether by lastname,
    firstname, etc. i put a condition that the query won't include results that
    has no firstname. when i run the program it still includes those with no
    firstnames but it has no errors.

    --
    Message posted via DotNetMonster.c om
    Best online pokies for real money in Australia and learn about safety and game mechanics in this comprehensive guide.


  • Jack Jackson

    #2
    Re: query

    On Tue, 15 Apr 2008 04:16:52 GMT, "enrico via DotNetMonster.c om"
    <u41845@uwewrot e:
    >Dim sSql As String = " SELECT tbltrcclient.Cl ientID, tbltrcclient.La stname,
    >tbltrcclient.F irstname, tbltrcclient.Ba rangay, tbltrcclient.Ty peofSeed,
    >tbltrcclient.T ypeofArea, tbltrcclient.He ctares FROM tbltrcclient WHERE
    >tbltrcclient.F irstname <' '
    >AND tbltrcclient.La stname LIKE " & Quote(TextBox2. Text) _
    >OR tbltrcclient.Fi rstname LIKE " & Quote(TextBox3. Text) _
    >OR tbltrcclient.Ba rangay = " & Quote(ComboBox6 .Text) _
    >OR tbltrcclient.Ty peofSeed = " & Quote(ComboBox1 .Text)
    >
    >If (ComboBox3.Text <" ") Then
    sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox3 .Text)
    End If
    If (ComboBox2.Text <" ") Then
    sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox2 .Text)
    End If
    >
    >myd = .runQuery(sSql)
    >
    >this is my search query where a user can search whether by lastname,
    >firstname, etc. i put a condition that the query won't include results that
    >has no firstname. when i run the program it still includes those with no
    >firstnames but it has no errors.
    I think you are combining AND and OR without parentheses. You are
    assuming that the backend will treat this like:

    condition AND (condition OR condition OR condition)

    but most lilely it does it like this:

    (((conditioin AND condition) OR condition) OR condition)

    But it is hard to tell because your example has many syntax errors.

    Comment

    • Armin Zingler

      #3
      Re: query

      "enrico via DotNetMonster.c om" <u41845@uweschr ieb
      Dim sSql As String = " SELECT tbltrcclient.Cl ientID,
      tbltrcclient.La stname, tbltrcclient.Fi rstname,
      tbltrcclient.Ba rangay, tbltrcclient.Ty peofSeed,
      tbltrcclient.Ty peofArea, tbltrcclient.He ctares FROM tbltrcclient
      WHERE tbltrcclient.Fi rstname <' '
      AND tbltrcclient.La stname LIKE " & Quote(TextBox2. Text) _
      OR tbltrcclient.Fi rstname LIKE " & Quote(TextBox3. Text) _
      OR tbltrcclient.Ba rangay = " & Quote(ComboBox6 .Text) _
      OR tbltrcclient.Ty peofSeed = " & Quote(ComboBox1 .Text)
      >
      If (ComboBox3.Text <" ") Then
      sSql &= " and tbltrcclient.Ty peofArea = " &
      Quote(ComboBox3 .Text) End If
      If (ComboBox2.Text <" ") Then
      sSql &= " and tbltrcclient.Ty peofArea = " &
      Quote(ComboBox2 .Text) End If
      >
      myd = .runQuery(sSql)
      >
      this is my search query where a user can search whether by lastname,
      firstname, etc. i put a condition that the query won't include
      results that has no firstname. when i run the program it still
      includes those with no firstnames but it has no errors.
      In addition to Jack, you should really make use of the Parameters
      property, but you do not even mention the database and/or technology you
      are using. I did not find "runQuery" anywhere searching in "All
      components" in VB IDE.


      Armin

      Comment

      • rowe_newsgroups

        #4
        Re: query

        On Apr 15, 12:16 am, "enrico via DotNetMonster.c om" <u41845@uwe>
        wrote:
        Dim sSql As String = " SELECT tbltrcclient.Cl ientID, tbltrcclient.La stname,
        tbltrcclient.Fi rstname, tbltrcclient.Ba rangay, tbltrcclient.Ty peofSeed,
        tbltrcclient.Ty peofArea, tbltrcclient.He ctares FROM tbltrcclient WHERE
        tbltrcclient.Fi rstname <' '
        AND tbltrcclient.La stname LIKE " & Quote(TextBox2. Text) _
        OR tbltrcclient.Fi rstname LIKE " & Quote(TextBox3. Text) _
        OR tbltrcclient.Ba rangay = " & Quote(ComboBox6 .Text) _
        OR tbltrcclient.Ty peofSeed = " & Quote(ComboBox1 .Text)
        >
        If (ComboBox3.Text <" ") Then
        sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox3 .Text)
        End If
        If (ComboBox2.Text <" ") Then
        sSql &= " and tbltrcclient.Ty peofArea = " & Quote(ComboBox2 .Text)
        End If
        >
        myd = .runQuery(sSql)
        >
        this is my search query where a user can search whether by lastname,
        firstname, etc. i put a condition that the query won't include results that
        has no firstname. when i run the program it still includes those with no
        firstnames but it has no errors.
        >
        --
        Message posted via DotNetMonster.c omhttp://www.dotnetmonst er.com/Uwe/Forums.aspx/dotnet-vb-net/200804/1
        Sql Injection Anyone?

        You might want to do some research on that before going live with your
        code - concatenating SQL expressions is extremely dangerous. I would
        highly suggest you at least use parameterized queries, if not full
        blown stored procedures. These will also clean up your code greatly
        and most likely fix your problem.

        Thanks,

        Seth Rowe [MVP]

        Comment

        Working...