Wrox Programmer Forums
|
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 July 24th, 2006, 06:05 PM
Authorized User
 
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default a blank date field

I have a form with a Calendar control and text field. IF the user wants to pick a date it can choose from the Calendar and it wioll pop up in the textbox control. But if it does not choose anything it should accept null value
.
here is my code

if(txtreviewdate.Text.Trim()=="")
            {
                sqlCommand4.Parameters["@ReviewDate"].Value =null;
            }
            else
            {
                sqlCommand4.Parameters["@ReviewDate"].Value = txtreviewdate.Text;
            }

But if I run is code it says that @revies date is missing from the stored procedure. Ten if I put the date then it accepts.
Please help so that it accepts a blank date field

 
Old July 24th, 2006, 10: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
Default

You can not pass the C# Null keyword into SQL like that because, as you have seen, it will bomb the stored procedure.

Instead you need to use the DBNull class to let the stored procedure know that you are passing NULL data into it so you would do something like this: (I assume you are working with MSSQL)

sqlCommand4.Parameters["@ReviewDate"].Value = DBNull.Value;

That should work for you. Hth.

"The one language all programmers understand is profanity."
 
Old July 25th, 2006, 11:29 AM
Authorized User
 
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much. It worked.Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
display blank instead of 0 in a field kawalsingh28 Crystal Reports 1 November 14th, 2006 03:00 AM
Adding a blank line to a memo field Scootterp Access VBA 3 October 31st, 2006 01:15 PM
Hidden field won't turn blank wirerider ASP.NET 2.0 Basics 1 February 28th, 2006 06:37 PM
Cannot make ‘databound’ date textbox null / blank? dlsc C# 0 August 12th, 2005 12:57 AM
;nsbp saved when field blank Lee8mm VB.NET 2002/2003 Basics 5 July 22nd, 2003 08:33 PM





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