Link to home
Start Free TrialLog in
Avatar of NP2322
NP2322Flag for United States of America

asked on

Multiple Search Criteria in SQL for ASP.Net(VB)

I'm trying to create a search engine which i'm sure someone here has probably created or something similar, might as well not recreate the wheel. I'm using a SQL database and ASP.Net (VB). I want to be able to search the database from a search page (calibration.aspx) with the following on the page:

The colums will be loaded into a drop down box where you will be able to select what column you want to search. Next to the drop down box will be an operator box where you will be able to choose whether you want to do a search taht is >, <, or = to the text box next to it on the right. This text box will be the value you are looking for in that column.

Now here's the tricky part for me. I want to be able to have a button underneath so that when you click it, you can have another search criteria right underneath it. It's cleaner this way instead of just listing 4 rows of search criteria.

Let me know if you need anymore info. The sooner the better.

Thanks in advance!
Avatar of ullfindsmit
ullfindsmit
Flag of United States of America image

save the search criterias in a datatable which you store in the session

when they click "add another criteria" you add a row to the criteria table

so here's a concept code on it

sub page_load()
 if not ispostback then
  dim dtCriteria as new datatable
  dtCritiria.columns.add( "comparename") ' this comes from your field dropdown
  dtCriteria.columns.add( "compareType") ' this comes from your second dropdown
  dtCriteria.columns.add( "compareValue") 'the values to comapre with
  session("criteria") = dtCriteria
 end if
end sub
now when the user clicks on addCriteria button

sub addCriteria_click(.....)
  dim dr as datarow
  dim dtCriteria as datatable
  dtcriteria = session("criteria")
  dr  = dtCriteria.newrow
  dr("comparename") = ddlCompare.selectedvalue
  dr("compareType") = ddlCompareType.selectedValue
  dr("compareValue") = txtValue.text
  dtCriteria.rows.add( dr )

  session( "criteria") = dtCriteria
end sub

you can use a datagrid and assign the dtCriteria as its datasource
make sure you rebind it on the addCriteria_click event as well


hoep this helps
-Smit.
Avatar of NP2322

ASKER

I'm sort of new to ASP.Net so some of the things you are saying are kind of confusing.

1. save the search criterias in a datatable which you store in the session

- Could you be a bit more detailed with this part? by datatable do you mean i should use a sql table?

2. dim dtCriteria as new datatable

- I guess this would stem from the first question, when i pasted it into the page, datatable was unrecognized.

3. you can use a datagrid and assign the dtCriteria as its datasource. make sure you rebind it on the addCriteria_click event as well

-I understand using the data grid part, but i'm a bit confused with the rebind.


Thanks
ASKER CERTIFIED SOLUTION
Avatar of ullfindsmit
ullfindsmit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin