Bind multiple selections to a query

J

John Hoge

I'm looking for that elusive .net time saving magic.

I have an application that presents a list of items which the user can
select from. A CheckBoxList works great for that, but I want to query
a database based on their selections.

I'm forced to dynamically building a SQL statement in a method I could
have done easily in classic ASP:

SELECT fields FROM tablename WHERE ID IN (value1,value2....)

where the values correspond to the boxes checked in the CheckBoxList
control.

With all the hype about the .net revolution from MS, shouldn't there
be a better way? I'm hoping to just say "select records whose ID
numbers correspond to the boxes checked" without the grind of building
and testing SQL strings with code.

Do I need to wait for .net 3.0?

John
 
K

Kevin Spencer

I'm forced to dynamically building a SQL statement in a method I could
have done easily in classic ASP:

I have no idea to what this is referring, as you didn't mention it (you only
mentioned a CheckBoxList). But I can tell you this: You're not forced to do
anything. In .Net, there are about a dozen ways to get data from a database,
and a dozen ways to bind it to a Control.

I used Classic ASP from the time it first emerged, and I would never go
back. Yes, I had to work very hard for a long time to learn .Net. But now I
would never look back. In Classic ASP, you would have had to create an
instance of (at least) a Connection, probably a RecordSet, and execute your
query. Then you would have had to hand-write all the ASP/HTML code to build
a table and/or a set of Checkboxes, and then wire them up by hand to the
appropriate fields in the RecordSet, possibly work out a way for the
Checkboxes to retain their values if the page was posted back to itself,
etc. I have to believe that the only reason you find that "easy" is that you
already know how to do it, and don't like the work involved in learning this
new, powerful, but complex technology. But learning new technologies is a
requirement in this business!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
J

John Hoge

Kevin,

Is there a technique that you can think of to pull information from a
database based on the (possibly multiple) selections from a
CheckBoxList?

The Classic ASP method would be to build a SQL statement string
manually, using the IN construct.

SELECT fieldlist from DATABASE where PRIMARYKEYFIELD IN
(valueA,valueB....)

Is there some .net way of passing an array of parameters to a database
to avoid this?

Thanks,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top