473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Binding optional parameters

I have a web page with various controls that supply parameters to an
ObjectDataSource. The ObjectDataSource has various methods that allow for
filtering of the results...GetProductsByID(), GetProductsByIDAndDate()...etc

Because the parameters are optional, I have to make a methods that take all
variantions of these parameters, so if I have 3 parameters, I need 7
methods, I then have to write code to call the correct method depending on
which parameters have been selected.

I am just wondering if there is an easier way to do this - maybe have one
method with all parameters and then let the ObjectDataSource determine the
parameters on the query?

--
Best regards
Mark
Sep 25 '06 #1
4 1926
Write a stored procedure that accepts the parameters. The select ends up
something like:

SELECT * FROM Table1
WHERE ((column1 = @column1) OR (@column1 IS NULL))

repeat for other optional parameters.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Mark Baldwin" <sW*****@community.nospamwrote in message
news:ux**************@TK2MSFTNGP04.phx.gbl...
>I have a web page with various controls that supply parameters to an
ObjectDataSource. The ObjectDataSource has various methods that allow for
filtering of the results...GetProductsByID(),
GetProductsByIDAndDate()...etc

Because the parameters are optional, I have to make a methods that take
all variantions of these parameters, so if I have 3 parameters, I need 7
methods, I then have to write code to call the correct method depending on
which parameters have been selected.

I am just wondering if there is an easier way to do this - maybe have one
method with all parameters and then let the ObjectDataSource determine the
parameters on the query?

--
Best regards
Mark

Sep 25 '06 #2
Hi Mark,

IMO, I would suggest you create a single method which take the maximum
count of parameters and determine the select/filter code logic in this
method(or you can create several private/internal helper methods which do
select/filter according to the different paramter combinations). This is
because ObjectDataSource can only be configured to use a single Select
method at a time and it is not quite good to change it at runtime, so it's
better to only expose one public select method in our business logic class.
As Gregory mentioned, you can check the paramter value and do select
filtering in stored procedure(at database layer). Instead, you can also
move the parameter checking and select/filter logic in business class code.
It's up to you according to the detailed scenario.

If you have any further questions, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 26 '06 #3
Hi Mark,

Have you got any further ideas on this issue? If you have any other
questions like to discuss on this , please feel free to post here.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 28 '06 #4
I have modified my project to use a business layer. This meant removing all
of the SqlDataSource objects and replacing them with ObjectDataSource. These
then link to the code in the business layer that includes one function that
takes all possible arguments, which DataSet method is called to get the data
however, depends on which parameters are passed.

Seem to work great! Thanks for your help...

--
Best regards
Mark

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:JR**************@TK2MSFTNGXA01.phx.gbl...
Hi Mark,

Have you got any further ideas on this issue? If you have any other
questions like to discuss on this , please feel free to post here.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
12
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without...
0
by: Steven Bolard | last post by:
Hello, I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am trying to get my webservices to run and although i can compile them and and get wsdl and service descriptions...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
by: peridian | last post by:
This is more of a general question, but I didn't know where to post it. Since Java is an example of a language which does this, I thought here would work. Coming from a C++ background, having...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.