Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 19th, 2007, 03:54 PM
Registered User
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple values in "IN" clause - Please help!

visual web developer 2005. vb.

I have a label that is being populated from a checklistbox on a previous page. If I have one item selected and the label = P3; the "WHERE DocType IN (@DocType)) in my gridview of a SQL table is working fine. When more then one item is selected and the label = P3,P4 ;I am not getting any records in my gridview. Please help!!!! I've tried to put single quotes around the values, but that does not work.
Old October 19th, 2007, 04:12 PM
Wrox Author
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

When you have multiple values, what does your SQL Statement literally equate to?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
Old October 20th, 2007, 06:31 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

In SQL the multi value string will result in something like this:

   WHERE DocType IN ("P3,P4")

This is treated as a single value. This what you need:

   WHERE DocType IN ("P3","P4")

This is two distinct values within the IN clause.

The problem is that you can not use a single SQL parameter to pass multiple values. You need to dynamically construct the SQL query.

Old October 22nd, 2007, 10:03 AM
Registered User
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

ok, I have the following to build my sql command which I belive is building correctly, but how do I get the SqlDataSource to have the statement in it?.

Dim selectcommand As String
        selectcommand = "SELECT * FROM [TMP_APAudit] WHERE "
        Dim loopcntr As Integer = 0
        Dim i As Integer
        For i = 0 To chktext.Items.Count - 1
            If chktext.Items(i).Selected Then
                If loopcntr = 0 Then
                    loopcntr += 1
                    selectcommand += "DocType = '" + chktext.Items(i).Value + "'"
                    selectcommand += " OR DocType = '" + chktext.Items(i).Value + "'"
                End If
            End If
        lblsqlcmd.Text = selectcommand

       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AXDemoConnectionString %>"
            SelectCommand= ???>

Old October 22nd, 2007, 04:10 PM
Registered User
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

OK... I finally figured it out. things are much easier when you know what to do. thanks.

Old October 22nd, 2007, 05:23 PM
Friend of Wrox
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts

So what's the answer? How'd you solve it?

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB WHERE clause for Recent Values Rich57 ASP.NET 2.0 Basics 2 February 21st, 2008 01:11 PM
How t o insert multiple values qazi_nomi Access ASP 2 May 3rd, 2005 12:45 AM
multiple selects -single where clause collie SQL Server 2000 3 January 21st, 2005 01:27 AM
Listboxes with Multiple Values joanncae BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 October 13th, 2003 12:13 PM
Multiple Values Search .. qwprince Classic ASP Databases 1 July 22nd, 2003 10:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.