We help IT Professionals succeed at work.

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

NP2322
NP2322 asked
on
1,685 Views
Last Modified: 2012-05-05
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!
Comment
Watch Question

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.

Author

Commented:
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
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Forced accept.

Computer101
EE Admin

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.