Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

ASP.NET TableAdapter Parameters IN Query

I'm using a TableAdapter and the query looks similar to the following:

SELECT * FROM Table WHERE Type In (@type)

From my ASP.NET page, the type can either be All, A, B, or C (All should incorporate A, B, & C).  The query works with a single parameter (meaning A, B or C) but when I select the "All" option the query doesn't return any rows.  

Does anyone have any suggestions on how to query the table using a drop down list with the values "All", A, B, or C?
0
mmeisel
Asked:
mmeisel
1 Solution
 
spprivateCommented:
Currently when you select All the query will become
SELECT * FROM Table WHERE Type In ('All') which will return none.
You have to somehow manipulate the code where you set the parameter to like this.
Where you set the value for @ type
put a conditon
if(ddl.selectedvalue='All')
{
param  = 'A,B,C')
}
Now this is a crude way of doing it.The efficient and neat way is to do it in stored procedure and check in sp if you want to pull specific value or all values
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now