Re: Passing a null value as date to SQL

From: Bernie Yaeger (berniey_at_cherwellinc.com)
Date: 10/25/04


Date: Mon, 25 Oct 2004 14:55:31 -0400

Hi Amber,

cLP.DateApproved = DBNull.value
should work.

HTH,

Bernie Yaeger

"amber" <amber@discussions.microsoft.com> wrote in message
news:5FC5EF9B-56D1-41EE-AB42-40C1E5954435@microsoft.com...
> Hello,
>
> I've been told that the experts here will be able to help me :)
>
> I'm using VB.NET and SQL Server.
> I'm using stored procedures to update and create new records in my
> database.
> On the form I'm working on, I have 2 date fields.
> I want the user to have the option of leaving these blank.
> I do not want default values.
> I'm getting error messages not matter what I try.
> What syntax can I use to get VB to pass this null value instead of a date,
> into SQL??
>
> I have created a custom class (cLP), which contains two date values
> (dateApproved is one).
> The column DateApproved in the table is set to accept null values.
>
>
> If I use the code:
> cLP.DateApproved = Convert.DBNull.value
>
> I get the error:
>
> An unhandled exception of type 'System.InvalidCastException' occurred in
> microsoft.visualbasic.dll
>
> Additional information: Cast from type 'DBNull' to type 'Date' is not
> valid.
>
> TIA,
>
> Amber
>



Relevant Pages

  • Re: Is it possible to set null value back in SQL server 2000?
    ... HTH, ... Bernie Yaeger ... > I have a column 'date' is datetime type and allow null value in SQL server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Max length of SQL statement, is there one?
    ... 128 megs (sql server 2000). ... HTH, ... Bernie Yaeger ... > Is there a max length for a select, insert or update statement? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SQL Adaptor - Timeout
    ... I have changed the host 'Max. number of message engine threads per CPU. ... to be 3 instead of 20 and I have the same error messages. ... Server stored procedures using SQL Server Adaptor. ...
    (microsoft.public.biztalk.general)
  • Re: Passing a null value as date to SQL
    ... When passing value to a SqlParameter then you have to use DBNull.Value. ... "amber" wrote in message ... > I'm using VB.NET and SQL Server. ... > I'm getting error messages not matter what I try. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SqlConnection.Open() Which ErrorCodes
    ... goes wrong during the connection phase. ... sys.messages system table for the message_id and text of SQL Server ... See the error messages topic in SQL Books Online. ...
    (microsoft.public.dotnet.framework.adonet)