Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Searching using OLEDB

    I am trying to create a search system on my site using records from an oledb database. So far I have managed to create a textbox for keywords. When the user submits their search they are redirected to a page with a querystring with their keywords in. For example: searchresults.aspx?keywords=example. I then want to be able to display all records through a datagrid where there is a word in the querystring that matches a word in the 'Subject' Field of my 'News' table. Currently I am just using a WHERE clause. For example: WHERE Subject='" & Request.QueryString("Keywords")"'. But this isn't very useful as the words searched for must be the exact words in the 'Subject' Field for the record to be displayed. Is there a way of displaying records where only one of the words in the querystring matches one of the words in the field 'Subject'?

    If there is, is there also a way of ordering the displayed records according to how many words match.

    If anyone knows how to do this it would be very much appreciated if you shared with me how to do it as I can't think how to do it.

    Thanks,
    Curt.

  • #2
    New Coder
    Join Date
    Oct 2005
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How much u have tried for this?
    Can you give some code snipset it will help me to answer you.

    Regards
    Abhi
    Handshakeit

    Quote Originally Posted by CurtWRC
    I am trying to create a search system on my site using records from an oledb database. So far I have managed to create a textbox for keywords. When the user submits their search they are redirected to a page with a querystring with their keywords in. For example: searchresults.aspx?keywords=example. I then want to be able to display all records through a datagrid where there is a word in the querystring that matches a word in the 'Subject' Field of my 'News' table. Currently I am just using a WHERE clause. For example: WHERE Subject='" & Request.QueryString("Keywords")"'. But this isn't very useful as the words searched for must be the exact words in the 'Subject' Field for the record to be displayed. Is there a way of displaying records where only one of the words in the querystring matches one of the words in the field 'Subject'?

    If there is, is there also a way of ordering the displayed records according to how many words match.

    If anyone knows how to do this it would be very much appreciated if you shared with me how to do it as I can't think how to do it.

    Thanks,
    Curt.

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Here is what I have done so far:

    http://www.rallystuff.net/curt/gener...?action=search

    Currently only the 'news' search has any code attached to it. Try searching for 'links' and you will be re-directed to this page:

    http://www.rallystuff.net/curt/gener...&Keyword=Links

    It should display the news article called 'Links'. However if there was a news article called 'More Links' I would like that to also be displayed as it contains the word 'Links'.

    To display the records I am using this clause:
    Code:
    "SELECT [News].* FROM [News] WHERE Subject='" & Request.QueryString("keyword") & "'"

  • #4
    New Coder
    Join Date
    Oct 2005
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try out this

    It should display the news article called 'Links'. However if there was a news article called 'More Links' I would like that to also be displayed as it contains the word 'Links'
    .

    For this u can modify your query like this
    Code:
    "SELECT [News].* FROM [News] WHERE Subject like %'" & Request.QueryString("keyword") & "%'"
    this will check any string that containg the keyword string.

    Thanx
    Abhi
    Handshakeit

  • #5
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    I just tried this using the search text 'Version' in hope that it would display the news article 'Version 2' as that has the word 'Version' in it:

    http://www.rallystuff.net/curt/gener...eyword=version

    However I got this error:
    Syntax error in query expression 'Subject like %'version%''.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Syntax error in query expression 'Subject like %'version%''.

  • #6
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Sorry for double posting, but I have just had a play around with that code and have changed it to this and now it works great!

    Code:
    "SELECT [News].* FROM [News] WHERE Subject like '%" & Request.QueryString("keyword") & "%'"
    Thanks handshakeit

  • #7
    New Coder
    Join Date
    Oct 2005
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks handshakeit
    Your Welcome
    Sorry form mistake in the query text

    Handshakeit


  •  

    Posting Permissions

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