DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Searching for a string in a table in a database...

  1. #1
    Join Date
    Apr 2005
    Posts
    53

    Searching for a string in a table in a database...

    Hi, Basically, Im making a little program to sort out my music collection. However, I have put in a MSflex grid and added the database and you can add entries etc which is all working fine. However, I was wondering if it is possible to search by Artist name etc a string in a table of the database? So basically i want to be able to search for an artist in my music collection?

    Is this possible and if so pleqase oculd someone show me how t do it...

    Thanks alot,

    Jenks

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Please read http://www.officecomputertraining.co...ges/page37.asp . The SQL statement to search your database by artist name will be something like, "SELECT * FROM TableName WHERE ArtistName = 'Bob Dylan'".
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2005
    Posts
    53

    :(

    i can't seem to get it to work..is there any chance anyone could post some example code up here?

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    which database are you using? Phil's suggestion should work with any database, but you have to replace TableName and ArtistName with the names you have used in your database. Post the code you wrote so far.
    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  5. #5
    Join Date
    Apr 2005
    Posts
    53

    Red face

    Private Sub Form_Load()
    'the format string just lets you define a format for how
    'your flexgrid will appear
    MSFlexGrid1.FormatString = "Title |" & _
    "Artist | Genre"

    'make sure the search path to the db is always in the right spot
    Data1.DatabaseName = App.Path & "\CDCollection.mdb"

    'set up the recordsource for the datasource and flexgrid control
    'in this case, it's just a raw SQL query, simple simple.
    Data1.RecordSource = "select * from CDs order by Title"
    that is my code that open up the database into a MSFlexgrid.

    then I wanna add a button and a text.text to search the database by title and then like just highlight or in some way show up the search results...

    I tried something like was said earlier but couldnt get it to work

    any help will be much appriacheted.

    Jenks

  6. #6
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    data1.Recordsource = "select * from CDs where XXXXX = '" + text1.text + "'"

    replace XXXX with the name of the record field you use to store the name of the artist in the database

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You may also have to Refresh the data control after changing the RecordSource.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center