Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 September 12th, 2005, 05:34 PM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing values from multiple list box

Hello everyone,

I am really having hard time to retrieve data from database using multiple list box. Here is the my simplified version of codes that you may want to take look...

<select NAME="Supplier" SIZE=4 MULTIPLE >
<%While NOT rsMain.EOF%>
<option value=<%=rsMain("Supplier Name")%>><%=rsMain("Supplier Name")%></option>
<%rsMain.MoveNext()
Wend%>
</select>


<INPUT TYPE="BUTTON" NAME="open" VALUE="SUBMIT" ONCLICK="outputSelected(this.form.Supplier.options )">

<SCRIPT LANGUAGE="JavaScript">

   function getSelected(opt) {
      var selected = new Array();
      var index = 0;
      for (var intLoop=0; intLoop < opt.length; intLoop++) {
         if (opt[intLoop].selected) {
            index = selected.length;
            selected[index] = new Object;
            selected[index].value = opt[intLoop].value;
            selected[index].index = intLoop;
         }
      }
      return selected;
   }

         function outputSelected(opt) {
            var sel = getSelected(opt);
            var strSel = "";
            for (var item in sel)
            //alert (sel[item].value)
               strSel += sel[item].value + "\n";
               alert("Selected Items:\n" + strSel);
            window.location='SupplierFilterTest.asp?Supp=' + strSel;

         }
      </SCRIPT>

<%SSupp= Request("Supp")%>

strOpenPO= "SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER ='" &SSupp& "'"

When I take a look inside SSupp, all variables are appending each other without any space.

When I select only one value from list box, my code is working fine. But whenever I select more than one, I get nothing.

Any help would be appreciated,

Thanks,

-Tulin

 
Old September 19th, 2005, 04:42 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii,
 Use
strOpenPO= "SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER in (" & SSupp & ")"

since ur below query expects SUPPLIER=VALUE
and you need 'in' or 'exists' calause so that it can retrieve all other values in the list
(
strOpenPO= "SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER ='" &SSupp& "'")


Hope this will help you





Cheers :)

vinod
 
Old September 19th, 2005, 03:21 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi,

Not clear on what you're trying to do here.

Are you trying to post to another page and count PO's for muliple supplier's?

 
Old September 21st, 2005, 01:52 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Rstelma!!

Suppose A,B,C are list of suppliers in ur listbox

Check the query (when u select only one supplier)
SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER ='A'

and
when u r selecting multiple values,ur queriy will be
SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER ='A,B,C'
offcourse above query wont result wht u want.

so u can use below one

SELECT Count(PONUMBER) AS OpenPos FROM MyTable WHERE SUPPLIER in(A,B,C)

Hope this will help you


now hope u got the clue.


Cheers :)

vinod
 
Old September 28th, 2005, 03:59 PM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it works finally...

But I have been experiencing different problem. There is a special characters (eg &, #, ?) in the SSupp variables(eg Tech&Lease). How can I get these values without error.

Thanks,

 
Old September 29th, 2005, 03:24 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post the errors you are getting and the offending code?

Cheers,

Chris

 
Old September 29th, 2005, 08:13 AM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the error:
------------------------------------
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression 'SUPPLIER IN ()'.
------------------------------------
I am getting this error when I select the value(s) with special characters(e.g. Tech&Lease).

 
Old September 29th, 2005, 08:30 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Please post the query you are trying to run

 
Old September 29th, 2005, 08:58 AM
Authorized User
 
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"SELECT Count(PONUMBER) AS OpenPos FROM [qry PO_data calculated fields final] WHERE SUPPLIER IN (" &SSupp& ")"

 
Old September 29th, 2005, 09:06 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you are using an in clause on a string field, you need to surround the criteria in quotes, so your query should look something like:
Code:
SELECT Count(PONUMBER) AS OpenPos FROM [qry PO_data calculated fields final] WHERE SUPPLIER IN ('Tech&Lease');
If you are just searching for one supplier, you could just use:
Code:
SELECT Count(PONUMBER) AS OpenPos FROM [qry PO_data calculated fields final] WHERE SUPPLIER = 'Tech&Lease';






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
passing values from multiple list box tulincim Javascript 4 September 14th, 2005 02:02 AM
passing values from multiple list box tulincim Classic ASP Basics 4 September 13th, 2005 06:40 PM





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