Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 April 25th, 2004, 05:31 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Using Parameters

Hi guys,

can you use parameters to select everything from a column??

For example I have a column called areas, a person enters an area and that area is put into the SQL statement. But I want to have a selection where the person can select all the areas for this column. Is this possible using parameters??

Any Ideas??

Adz - The World is not enough
__________________
Adz - Learning The J2EE Ways.
 
Old April 26th, 2004, 12:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

if u r using Textbox u can choose ComboBox instead!
its all from me! Sorry but u were not CLEAR!

Always:),
Hovik Melkomian.
 
Old April 27th, 2004, 03:22 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

I have a dropdownlist which has many area values i.e Portsmouth, Southampton, Northampton, all, one of the values within the drop down list is all. This value, when selected should show all the types of selections. I am using parameters to to select from the database. I want to know how to select everything from a column using parameters, here is my code: -

objCommand.Parameters.Add("RentingPrice", OleDbType.Integer, 6, "RentingPrice");
  objCommand.Parameters.Add("HouseHold", OleDbType.VarChar, 32, "HouseHold");
  objCommand.Parameters.Add("Smoking", OleDbType.VarChar, 32, "Smoking");
  objCommand.Parameters.Add("Furnished", OleDbType.VarChar, 32, "Furnished");

  objCommand.Parameters["RentingPrice"].Value = Payment.Text;
  objCommand.Parameters["HouseHold"].Value = strAreaFilter;
  objCommand.Parameters["Smoking"].Value = strSmokingFilter;
  objCommand.Parameters["Furnished"].Value = strFurnished;

strAreaFilter gets it value from the dropdownlist. It uses OleDbType.VarChar, I dont kow if you can use this to select everything?? Any ideas guys??



Adz - The World is not enough
 
Old April 27th, 2004, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You shouldn't supply the parameter if you want all records. Usually you supply parameters when you want to limit the criteria returned. What does your SQL look like?

Brian
 
Old April 27th, 2004, 07:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Alternativly, you can pass in null (using DBNull.Value) as the parameter's value.

Then inside your sproc you can compare the parameter with null and have all records returned. Something like this:
Code:
...
@HouseHold varchar(32)
...
SELECT Column1, Column2 FROM MyTable WHERE (HouseHold = @HouseHold OR @HouseHold = null)
When @HouseHold has a value, all records with the matching HouseHold will be filtered. If @HouseHold is null, the test will return true for all records (as @HouseHold is null all the time) and all records are returned.

To assign the value to your paramaters collection try something like this:
Code:
if (strAreaFilter.Length > 0)
{
  objCommand.Parameters["HouseHold"].Value = strAreaFilter;
}
else
{
  objCommand.Parameters["HouseHold"].Value = DBNull.Value;
}
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameters dcct84 C# 6 September 27th, 2007 05:26 PM
parameters dpkbahuguna ASP.NET 1.x and 2.0 Application Design 0 April 3rd, 2007 07:27 AM
Parameters Dharam80 Access 3 August 19th, 2005 01:59 PM
Parameters coolerbob VB.NET 0 March 9th, 2004 12:48 PM





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