Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SessionParameter DefaultValue DBNull

Posted on 2007-11-13
6
Medium Priority
?
1,417 Views
Last Modified: 2008-02-01
Hi there,

This may seem like an easy question but I can't seem to get it to work. I've got a SessionParameter in a SqlDataSource with a SelectCommandType of StoredProcedure. If the SessionParameter is null/nothing I need to pass the stored procedure a value of System.DBNull.Value. How do I do that?

Thanks,
Aaron
0
Comment
Question by:CoconutTelegraph
  • 3
  • 3
6 Comments
 

Author Comment

by:CoconutTelegraph
ID: 20277200
btw, I've tried this but it doesn't seem to work....

<asp:SessionParameter Name="ProductID" DefaultValue="" ConvertEmptyStringToNull="true" SessionField="MySessionProductID" />
0
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 2000 total points
ID: 20277515
You need to handle the onSelecting event of the SqlDataSource
example
<asp:SessionParameter Name="ProductID" DefaultValue=""ConvertEmptyStringToNull="true" SessionField="MySessionProductID" Type="String"  />
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
        if (e.Command.Parameters["@ProductID"].Value==null)
            {
            e.Command.Parameters["@ProductID"].Value = DBNull.Value;
            }
        }

that should take care of it
0
 

Author Comment

by:CoconutTelegraph
ID: 20277559
Interesting. Can I ask you from a design perspective, which do you think is cleaner and better code?

1) Using the method you've suggested for setting the values to DBNull.Value when null.

2) Ditching the SqlDataSource, and opting to hit the database directly in the DataBinding event of the GridView and then attaching the returned ADO.Net DataTable to the DataSource property.

Hmmm. I can't decide now. :(

Anyhow thanks!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 20277727
I a not a fan of the SQLDataSource for a simple reason. It mixes data layer login with the UI layer
If you really have to use a control like the SqlDataSource, I would recommend using the ObjectDataSource.
take a look at the docs here

http://msdn2.microsoft.com/en-us/library/9a4kyhcx(vs.80).aspx

good luck
Sammy
0
 

Author Comment

by:CoconutTelegraph
ID: 20277738
Good point. Well that certainly gives me something to think about. Thanks for the quick and thorough response Sammy!

0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 20277790
You welcome and thanks for the Points
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question