Search in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    Search in database

    How can i search for all records starting with the string A or any other string inputeed by user.

    Thanx
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Use this Query and open the Recordset:

    "Select * From MyTable Where FieldName Like 'A*'"

    Regards
    Veena

    Comment

    • Ali Rizwan
      Banned
      Contributor
      • Aug 2007
      • 931

      #3
      Originally posted by QVeen72
      Hi,

      Use this Query and open the Recordset:

      "Select * From MyTable Where FieldName Like 'A*'"

      Regards
      Veena
      Hello Veena

      This is not working.
      I have used this code as

      Code:
      ADATA.CommandType = adCmdUnknown
          ADATA.RecordSource = "Select * From info Where Name Like '" & Text1.Text & "*'"
          ADATA.Refresh
      thanx

      Comment

      • 9815402440
        New Member
        • Oct 2007
        • 180

        #4
        hi

        use % in place of *

        You my use _ (underscore) and % (percent) as wild cards. Use _ for one character and % for many charaters.

        regards
        manpreet singh dhillon hoshiarpur

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Originally posted by Ali Rizwan
          How can i search for all records starting with the string A or any other string inputeed by user.

          Thanx
          use the following syntax

          select * from table_name where field_name like 'A%'

          if u r going for user input from textbox try this

          sqlstr="select * from table_name where field_name like '" & trim(text1.text ) & "%'"

          Comment

          • rizwan6feb
            New Member
            • Jul 2007
            • 108

            #6
            Which database you are using at the backend ?

            Microsoft Access uses '*' as the wildcard character, other Databases use '%'. For me there is no problem in the query if Microsoft Access is used at the backend.

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Originally posted by Ali Rizwan
              Hello Veena

              This is not working.
              I have used this code as

              Code:
              ADATA.CommandType = adCmdUnknown
                  ADATA.RecordSource = "Select * From info Where Name Like '" & Text1.Text & "*'"
                  ADATA.Refresh
              thanx
              Try This :

              ADATA.RecordSou rce = "Select * From info i Where i.Name Like '*" & Text1.Text & "*'"

              * at both sides, ensures, middle of the name will also be searched..

              Regards
              Veena

              Comment

              Working...