By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Search for single, and multiple keywords (NO ACCESS PROBLEM!!)

P: 9
CODE: ASP.NET with C#
DATABASE: ACCES


alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt know what to search for), but heres the problem:

I am making a search function for my website, i want this to be possible:
- search for 1 keyword (the problem guy)
- search for multiple keywords

things that alreaddy work (so no problem with those):
- sort by ddl
- search for ddl

The problem with my current code is:
i can search for multiple keywords, but not for just one.


the code where it occurs:
Expand|Select|Wrap|Line Numbers
  1. protected void btn_search_Click(object sender, EventArgs e)
  2.         {
  3.             sortby = dropdownlist_orderby.SelectedValue.ToString();
  4.             searchterm = box_searchfor.Text;
  5.             searchparameter = searchterm.Substring(searchterm.IndexOf(""), searchterm.LastIndexOf(" ")).ToString();
  6.             serialsearchin = ddl_searchforserialin.SelectedValue.ToString();
  7.  
  8.             string constring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("database.mdb");
  9.             string SQLvraag = "SELECT * FROM serials WHERE " + serialsearchin + " LIKE '%" + searchparameter + "%' ORDER BY " + sortby;
  10.             OleDbConnection dbconnectie = new OleDbConnection(constring);
  11.  
after this the results are being displayed, witch works aswell.

if i run the page, and search for a single keyword, i get the following error report:
Expand|Select|Wrap|Line Numbers
  1. 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.
  2.  
  3. Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
  4. Parameter name: length
  5.  
  6. Source Error:
  7.  
  8. Line 73:             sortby = dropdownlist_orderby.SelectedValue.ToString();
  9. Line 74:             searchterm = box_searchfor.Text;
  10. Line 75:             searchparameter = searchterm.Substring(searchterm.IndexOf(""), searchterm.LastIndexOf(" ")).ToString();
  11. Line 76:             serialsearchin = ddl_searchforserialin.SelectedValue.ToString();
  12. Line 77: 
  13.  
  14.  
  15. Source File: d:\Mijn Documenten\Keybase\serials.aspx.cs    Line: 75
  16.  
  17. Stack Trace:
  18.  
  19. [ArgumentOutOfRangeException: Length cannot be less than zero.
  20. Parameter name: length]
  21.    System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +2848177
  22.    System.String.Substring(Int32 startIndex, Int32 length) +11
  23.    serials.btn_search_Click(Object sender, EventArgs e) in d:\Mijn Documenten\Keybase\serials.aspx.cs:75
  24.    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
  25.    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
  26.    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
  27.    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
  28.    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
  29.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921
  30.  
Apr 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: 9
GOD I HATE IT WHEN THIS HAPPENDS :S
i post a message, and shortly after i find a solution :S

well il post it, might be usefull for others too!

Expand|Select|Wrap|Line Numbers
  1. searchparameter = searchterm.Replace(" ", "%' AND " + serialsearchin + " LIKE '%");
is the code i use instead of:
Expand|Select|Wrap|Line Numbers
  1. searchparameter = searchterm.Substring(searchterm.IndexOf(""), searchterm.LastIndexOf(" ")).ToString();
Apr 19 '07 #2

kenobewan
Expert 2.5K+
P: 4,871
Thanks for sharing the solution - I'm sure that it will help others :).
Apr 20 '07 #3

P: 9
Thanks for sharing the solution - I'm sure that it will help others :).
no problem, thats why i posted
May 14 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.