passing date values

D

douglas

I have the following two questions:

1. If a date field is passed to a c#.net 2005 application as null, what
code needed so that the vb.net application can handle the 'null' date and
work with it as a 'blank' field?
2. In a stored procedure that is called by the C#.net 2005 application, a
'blank date' is returned as '1/2/1900'. How would you pass the date as
'blank' instead of '1/2/1900' to the vb.net application? The following is the
stored procedure:
reate table testtable (tablekey as int,testdate as datetime)

insert into testtable values (1,getdate())

insert into testtable values(2,'')


The source for the first insert statement will contain a valid date.
The source for the second insert statement will not contain any date.
that is why I want the value in the second inswert statement to be blank.

Thus can you tell me how to pass a blank date value?
 
I

Ignacio Machin ( .NET/ C# MVP )

I have the following two questions:

 1. If a date field is passed to a c#.net 2005 application as null, what
code needed so that the vb.net application can handle the 'null' date and
work with it as a 'blank' field?
 2. In a stored procedure that is called by the C#.net 2005 application, a
'blank date' is returned as '1/2/1900'. How would you pass the date as
'blank' instead of '1/2/1900' to the vb.net application? The following isthe
stored procedure:

What is the VB app expecting and what it interpret as null
your code in C# can be:
DateTime nullDate = new DateTime(1900, 1, 2);
if ( returnedDate == nullDate)
CallVBMethod( nullInterpretationValue);
else
CallVBMethod( returnedDate);
 
P

Paul

Im prolly on the wrong track again but at least its friday.

One problem with Nullable Types is they do not pass over SOAP (unless they
fixed it) I Tend to create a method in a DataProvider Object. Beware of
Datetime over SOAP as SOAP is XML a conversion to string is done if the
webserver is a different region your date is wrong. You can get around this
with OADate and double but this probably would not work with Java or
anyother language that wants to consume a .net WSDL.

The big presumption of the code below is you will not need minvalue as a
valid datetime which apart from specific circumstances is more than likely.

e.g.

DateTime ReadDateTime(IDataReader reader, int fieldId)
{

if (reader.isdbnull(fieldId))
return DateTime.MinValue();
else
return reader.getDateTime(fieldId)

}

Object WriteDateTime(DateTime datetime)
{

if (datetime == DateTime.MinValue)
return DbNull.Value;
else
return datetime;

}

In your UI wrap a DataTime Format with similar code to above, returning an
empty string.

BTW never treat Dates as Strings (exception front end) if you can ever help
it, and certainly not across machine boundries.

insert into testtable values(2,null)

rather than

insert into testtable values(2,'')
 
S

sloan

I (and some others) answered your question in
microsoft.public.sqlserver.programming

Do NOT MULTI POST.

There are not "blank dates".

There are dates, which are nullable.

Read my post at microsoft.public.sqlserver.programming.
 
C

Cor Ligthert[MVP]

Paul,

In my opinion in this on the right track, however be aware that the OP has
spread this message all over the newsgroups as multipost.

So probably to much work, because he is probably answered wrong and right
everywhere.

For those who not understand this, this is related to a previous reply from
Paul in another threat.

:)


Cor
 
D

douglas

"Vipin Mehta" :

Can you tell me what you mean by nullable types? Can you show me some code
examples?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top