Bind multiple selections to a query

Discussion in 'ASP .Net' started by John Hoge, Nov 30, 2004.

  1. John Hoge

    John Hoge Guest

    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
    John Hoge, Nov 30, 2004
    #1
    1. Advertising

  2. > 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.

    "John Hoge" <> wrote in message
    news:...
    > 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
    Kevin Spencer, Nov 30, 2004
    #2
    1. Advertising

  3. John Hoge

    John Hoge Guest

    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
    John Hoge, Nov 30, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill yeager

    multiple listbox selections

    bill yeager, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    446
    bill yeager
    Aug 12, 2003
  2. =?Utf-8?B?QWRpcw==?=
    Replies:
    0
    Views:
    382
    =?Utf-8?B?QWRpcw==?=
    Oct 19, 2004
  3. Steffen Loringer

    Multiple selections in dropdownlist

    Steffen Loringer, Aug 11, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,345
    Mark Rae
    Aug 11, 2005
  4. Chris Kettenbach

    asp:ListBox multiple selections

    Chris Kettenbach, Oct 7, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    10,324
    S. Justin Gengo
    Oct 7, 2005
  5. Stian
    Replies:
    2
    Views:
    453
    Mark Parnell
    Sep 3, 2004
Loading...

Share This Page