Re: Passing a null value as date to SQL
From: Miha Markic [MVP C#] (miha)
Date: 10/25/04
- Next message: Bernie Yaeger: "Re: Passing a null value as date to SQL"
- Previous message: amber: "Passing a null value as date to SQL"
- In reply to: amber: "Passing a null value as date to SQL"
- Next in thread: Bernie Yaeger: "Re: Passing a null value as date to SQL"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 25 Oct 2004 20:53:16 +0200
Hi amber,
DateTime .net type can't be null.
One solution to store nullable type would be to use object instead or
something like
http://sourceforge.net/projects/nullabletypes/
When passing value to a SqlParameter then you have to use DBNull.Value.
-- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand.com "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 >
- Next message: Bernie Yaeger: "Re: Passing a null value as date to SQL"
- Previous message: amber: "Passing a null value as date to SQL"
- In reply to: amber: "Passing a null value as date to SQL"
- Next in thread: Bernie Yaeger: "Re: Passing a null value as date to SQL"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading