473,387 Members | 3,787 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,387 software developers and data experts.

loading an empty value into a date object using vb.net

Howdy,

I am trying to accomplish the following:

dim DateSend as date

if txtDateSend.text = "" then
DateSend = dbnull.value
else
DateSend = txtDateSend.text
end if

however, the script screams about "Value of type 'System.DBNull' cannot be
converted to 'Date'." How do I send a Null back? This variable, DateSend, is
then sent to a stored procedure and written back to the database. I read
other posts on google groups stating users switched the variables from date
to string, then did a cast within the proc. Is this really the best
solution? Come on, Microsoft must have a way of loading an empty value into
a date object.

thanks!!

David Lozzi
Nov 19 '05 #1
1 2920
DateTime is a value type (Date maps to DateTime with no time set), so it
cannot be set to null or dbnull (only reference types can be set to null
reference and even them cannot be set to dbnull.value, except object type
itself).

You can have DateTime.MinValue to indicate that the value has not been set
or is empty, and before setting the value to the parameter, check the
DateTime being MinValue and based on that pass DBNull straight to the proc
(or use default values in procs so you'd need to apss only parameters having
a value).

--
Teemu Keiski
ASP.NET MVP, Finland
"David Lozzi" <dlozzi@(remove)delphi-ts.com> wrote in message
news:en**************@TK2MSFTNGP09.phx.gbl...
Howdy,

I am trying to accomplish the following:

dim DateSend as date

if txtDateSend.text = "" then
DateSend = dbnull.value
else
DateSend = txtDateSend.text
end if

however, the script screams about "Value of type 'System.DBNull' cannot be
converted to 'Date'." How do I send a Null back? This variable, DateSend,
is then sent to a stored procedure and written back to the database. I
read other posts on google groups stating users switched the variables
from date to string, then did a cast within the proc. Is this really the
best solution? Come on, Microsoft must have a way of loading an empty
value into a date object.

thanks!!

David Lozzi

Nov 19 '05 #2

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

Similar topics

2
by: christopher.secord | last post by:
I would like have a little "loading..." tab not unlike the one that gmail uses and I would like to display that tab while an ajax call is made. The javascript to display the tab works. The...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
7
by: Matthew Wieder | last post by:
Hi - I have a datagrid that has a black header and the rows alternate white and gray. The problem is that until items are added to the grid, the grid appears as a large black rectangle, which is...
1
by: Reza | last post by:
Hi I have a column in my datagrid that can have values of null at times. I am not assigning any value to it, if it is coming from Database empty. Now, the problem is I guess the datetime variables...
2
by: Eric Maia | last post by:
I have a textbox (StartDateTextBox) in a UserControl on my page, that is supposed to have a date entered into it. I have a RequiredFieldValidator that has its ControlToValidate property set to the...
2
by: Rob | last post by:
I was working on a project and everything was going fine, then all of a sudden the form set as my startup object stopped loading. I tried setting some others as the startup object, and some of my...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
20
by: Nickolai Leschov | last post by:
Hello all, I am programming an embedded controller that has a 'C' library for using its system functions (I/O, timers, all the specific devices). The supplied library has .LIB and .H files. ...
2
by: Jeff | last post by:
Hi I'm trying to achieve a scenario where I have c# files that are compiled dynamically, the assemblies are then loaded in a different AppDomain, I call a simple method from the object, and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.