.NETGURU
Convert.ToDateTime
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


SNegussie@aol.com
Hi,

I'm using Convert.ToDateTime to convert a string representation of a date in
a TextBox. Here is what I'm doing:

DateTime cvDate;
cvDate = Convert.ToDateTime(textbox.Text);

This works fine if there is data in the text box, but fails if there is not
data in the text. So I want to check for the presence of data in the text
box before I do the conversion. So I check for the length of the textbox
value and perform the conversion if it contains text.

if (textbox.Text.Length !=0)
cvDate = Convert.ToDateTime(textBox.Text);
else
I want to set cvDate to null. How do I do that? I get an error when
I do

cvDate = null;

Thanks
S

DateTime. It works
Reply to this message...
 
    
Brian W. Spolarich
ICBUaGlzIGlzIHNvcnQgb2YgYSBwcm9ibGVtIGluIHRoZSAuTkVUIGZyYW1ld29yazogIGhvdyB0
byByZXByZXNlbnQgYW4gdW5pbml0aWFsaXplZCBvciBudWxsIHZhbHVlZCBEYXRlVGltZS4NCiAN
CiAgU2VlIGh0dHA6Ly9kaXNjdXNzLmRldmVsb3AuY29tL2FyY2hpdmVzL3dhLmV4ZT9TMj1kb3Ru
ZXQmTD1ET1RORVQmcT0mcz1kYXRldGltZStudWxsJmY9JmE9JmI9DQogDQogIGZvciBhIGRpc2N1
c3Npb24gb24gdGhpcyB0b3BpYy4NCiANCiAgUmVnYXJkcywNCiANCiAgLWJ3cw0KDQoJLS0tLS1P
cmlnaW5hbCBNZXNzYWdlLS0tLS0gDQoJRnJvbTogU05lZ3Vzc2llQGFvbC5jb20gW21haWx0bzpT
TmVndXNzaWVAYW9sLmNvbV0gDQoJU2VudDogU2F0IDcvNi8yMDAyIDY6NTAgUE0gDQoJVG86IGFz
cG5nY3MgDQoJQ2M6IA0KCVN1YmplY3Q6IFthc3BuZ2NzXSBDb252ZXJ0LlRvRGF0ZVRpbWUNCgkN
CgkNCglIaSwgDQoJDQoJSSdtIHVzaW5nIENvbnZlcnQuVG9EYXRlVGltZSB0byBjb252ZXJ0IGEg
c3RyaW5nIHJlcHJlc2VudGF0aW9uIG9mIGEgZGF0ZSBpbiBhIFRleHRCb3guICBIZXJlIGlzIHdo
YXQgSSdtIGRvaW5nOiANCgkNCglEYXRlVGltZSBjdkRhdGU7IA0KCWN2RGF0ZSA9IENvbnZlcnQu
VG9EYXRlVGltZSh0ZXh0Ym94LlRleHQpOyANCgkNCglUaGlzIHdvcmtzIGZpbmUgaWYgdGhlcmUg
aXMgZGF0YSBpbiB0aGUgdGV4dCBib3gsIGJ1dCBmYWlscyBpZiB0aGVyZSBpcyBub3QgZGF0YSBp
biB0aGUgdGV4dC4gIFNvIEkgd2FudCB0byBjaGVjayBmb3IgdGhlIHByZXNlbmNlIG9mIGRhdGEg
aW4gdGhlIHRleHQgYm94IGJlZm9yZSBJIGRvIHRoZSBjb252ZXJzaW9uLiAgU28gSSBjaGVjayBm
b3IgdGhlIGxlbmd0aCBvZiB0aGUgdGV4dGJveCB2YWx1ZSBhbmQgcGVyZm9ybSB0aGUgY29udmVy
c2lvbiBpZiBpdCBjb250YWlucyB0ZXh0LiANCgkNCglpZiAodGV4dGJveC5UZXh0Lkxlbmd0aCAh
PTApIA0KCSAgICAgIGN2RGF0ZSA9IENvbnZlcnQuVG9EYXRlVGltZSh0ZXh0Qm94LlRleHQpOyAN
CgllbHNlIA0KCSAgICAgIEkgd2FudCB0byBzZXQgY3ZEYXRlIHRvIG51bGwuICBIb3cgZG8gSSBk
byB0aGF0PyAgSSBnZXQgYW4gZXJyb3Igd2hlbiBJIGRvIA0KCQ0KCSAgICAgIGN2RGF0ZSA9IG51
bGw7IA0KCQ0KCVRoYW5rcyANCglTIA0KCQ0KCURhdGVUaW1lLiAgSXQgd29ya3MgfCBbYXNwbmdj
c10gbWVtYmVyIGJzcG9sYXJpY2hAbmVwaHJvc3RoZXJhcGV1dGljcy5jb20gPSBZT1VSIElEIHwg
aHR0cDovL3d3dy5hc3BsaXN0cy5jb20vYXNwbGlzdHMvYXNwbmdjcy5hc3AgPSBKT0lOL1FVSVQg
DQoNCg==

Reply to this message...
 
    
Stephen Rees
I'd set it to date time MinValue.
or
new System.DateTime(1900,01,01)

If you really need a null in the db then just say if cvdate == minvalue,
update db set date = null.

In other words, I can't seem to see a null/empty value in datetime either.

Steve.
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: 06 July 2002 23:51
To: aspngcs
Subject: [aspngcs] Convert.ToDateTime

Hi,

I'm using Convert.ToDateTime to convert a string representation of a date
in a TextBox. Here is what I'm doing:

DateTime cvDate;
cvDate = Convert.ToDateTime(textbox.Text);

This works fine if there is data in the text box, but fails if there is
not data in the text. So I want to check for the presence of data in the
text box before I do the conversion. So I check for the length of the
textbox value and perform the conversion if it contains text.

if (textbox.Text.Length !=0)
cvDate = Convert.ToDateTime(textBox.Text);
else
I want to set cvDate to null. How do I do that? I get an error
when I do

cvDate = null;

Thanks
S

DateTime. It works | [aspngcs] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT
Reply to this message...
 
    
Michael Wells
While I favor a stricter use of types, I tend to use objects in this
case. An object allows for nulls and storage of DateTimes, and with
reasonable discipline in your coding, you should have no real
side-effects.
=20
If you use DateTimes extensively with ADO.NET, you might also consider
developing a class to manage this, or at least consider partitioning
your validation & conversion code into some functions. =20

-----Original Message-----
From: Stephen Rees [mailto:Click here to reveal e-mail address]
Sent: Sunday, July 07, 2002 12:07 PM
To: aspngcs
Subject: [aspngcs] RE: Convert.ToDateTime

I'd set it to date time MinValue.
or=20
new System.DateTime(1900,01,01)

If you really need a null in the db then just say if cvdate =3D=3D =
minvalue,
update db set date =3D null.
=20
In other words, I can't seem to see a null/empty value in datetime
either.
=20
Steve.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: 06 July 2002 23:51
To: aspngcs
Subject: [aspngcs] Convert.ToDateTime

Hi,=20

I'm using Convert.ToDateTime to convert a string representation of a
date in a TextBox. Here is what I'm doing:=20

DateTime cvDate;=20
cvDate =3D Convert.ToDateTime(textbox.Text);=20

This works fine if there is data in the text box, but fails if there is
not data in the text. So I want to check for the presence of data in
the text box before I do the conversion. So I check for the length of
the textbox value and perform the conversion if it contains text.=20

if (textbox.Text.Length !=3D0)=20
cvDate =3D Convert.ToDateTime(textBox.Text);=20
else=20
I want to set cvDate to null. How do I do that? I get an error
when I do=20

cvDate =3D null;=20

Thanks=20
S=20

DateTime. It works | [aspngcs] member Click here to reveal e-mail address =3D YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT=20

| [aspngcs] member Click here to reveal e-mail address =3D YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT=20

Reply to this message...
 
    
Tim Musschoot
Whey convert it to NULL. This is not a valid timestamp...

I use this code:

DateTime cvDate;
try{
    cvDate =3D DateTime.Parse(textbox.Text);
}
catch
{
    cvDate =3D DateTime.Now;
}

This assurs you ALWAYS have a legal datetime value. You can use a =
boolean to mark the usefullness of the date.... :

DateTime cvDate;
bool b_cvDate;
try{
    cvDate =3D DateTime.Parse(textbox.Text);
    b_cvDate =3D true;
}
catch
{
    cvDate =3D DateTime.Now;
    b_cvDate =3D false;
}

-----Oorspronkelijk bericht-----
Van: Brian W. Spolarich [mailto:Click here to reveal e-mail address]
Verzonden: zondag 7 juli 2002 18:10
Aan: aspngcs
Onderwerp: [aspngcs] RE: Convert.ToDateTime

This is sort of a problem in the .NET framework: how to represent an =
uninitialized or null valued DateTime.
=20
See =
http://discuss.develop.com/archives/wa.exe?S2=3Ddotnet&L=3DDOTNET&q=3D&s=3D=
datetime+null&f=3D&a=3D&b=3D
=20
for a discussion on this topic.
=20
Regards,
=20
-bws

    -----Original Message-----=20
    From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]=20
    Sent: Sat 7/6/2002 6:50 PM=20
    To: aspngcs=20
    Cc:=20
    Subject: [aspngcs] Convert.ToDateTime
=09
=09
    Hi,=20
=09
    I'm using Convert.ToDateTime to convert a string representation of a =
date in a TextBox. Here is what I'm doing:=20
=09
    DateTime cvDate;=20
    cvDate =3D Convert.ToDateTime(textbox.Text);=20
=09
    This works fine if there is data in the text box, but fails if there is =
not data in the text. So I want to check for the presence of data in =
the text box before I do the conversion. So I check for the length of =
the textbox value and perform the conversion if it contains text.=20
=09
    if (textbox.Text.Length !=3D0)=20
     cvDate =3D Convert.ToDateTime(textBox.Text);=20
    else=20
     I want to set cvDate to null. How do I do that? I get an error =
when I do=20
=09
     cvDate =3D null;=20
=09
    Thanks=20
    S=20
=09
    DateTime. It works | [aspngcs] member =
Click here to reveal e-mail address =3D YOUR ID | =
http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT=20

jzri=01Djrj=20

Reply to this message...
 
    
Ryan Trudelle-Schwarz
One problem here is that date fields in a Database (such as SQL Server) =
can be null and that is a valid value for them, so there needs to be a =
logical way to mark the dates as null within the code to translate this =
to the database.=20

Personally, I usually create a struct that contains a date and a Boolean =
called "IsNull" and just check that value before using the date. Then =
check it when updating the db.

-> -----Original Message-----
-> From: Tim Musschoot [mailto:Click here to reveal e-mail address]
->=20
-> Whey convert it to NULL. This is not a valid timestamp...
->=20
-> I use this code:
->=20
-> DateTime cvDate;
-> try{
->     cvDate =3D DateTime.Parse(textbox.Text);
-> }
-> catch
-> {
->     cvDate =3D DateTime.Now;
-> }
->=20
-> This assurs you ALWAYS have a legal datetime value. You can use a
-> boolean to mark the usefullness of the date.... :
->=20
-> DateTime cvDate;
-> bool b_cvDate;
-> try{
->     cvDate =3D DateTime.Parse(textbox.Text);
->     b_cvDate =3D true;
-> }
-> catch
-> {
->     cvDate =3D DateTime.Now;
->     b_cvDate =3D false;
-> }
->=20
-> -----Oorspronkelijk bericht-----
-> Van: Brian W. Spolarich [mailto:Click here to reveal e-mail address]
->=20
-> This is sort of a problem in the .NET framework: how to represent =
an
-> uninitialized or null valued DateTime.
->=20
-> See
-> =
http://discuss.develop.com/archives/wa.exe?S2=3Ddotnet&L=3DDOTNET&q=3D&s=3D=
dateti
-> me+null&f=3D&a=3D&b=3D
->=20
-> for a discussion on this topic.
->=20
-> Regards,
->=20
-> -bws
->=20
->     -----Original Message-----
->     From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
->=20
->     Hi,
->=20
->     I'm using Convert.ToDateTime to convert a string representation of
-> a date in a TextBox. Here is what I'm doing:
->=20
->     DateTime cvDate;
->     cvDate =3D Convert.ToDateTime(textbox.Text);
->=20
->     This works fine if there is data in the text box, but fails if
-> there is not data in the text. So I want to check for the presence =
of
-> data in the text box before I do the conversion. So I check for the
-> length of the textbox value and perform the conversion if it contains
-> text.
->=20
->     if (textbox.Text.Length !=3D0)
->      cvDate =3D Convert.ToDateTime(textBox.Text);
->     else
->      I want to set cvDate to null. How do I do that? I get an
-> error when I do
->=20
->      cvDate =3D null;
->=20
->     Thanks
->     S

---
[This E-mail scanned for viruses by Declude Virus]

Reply to this message...
 
    
Brian Boyce
You can use System.DBNull or IsDbNull(object) to check for null values in
database fields, or indeed to pass a null value to a field through a
required stored procedure parameter.

Brian

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: 07 July 2002 23:44
To: aspngcs
Subject: [aspngcs] RE: Convert.ToDateTime

One problem here is that date fields in a Database (such as SQL Server) can
be null and that is a valid value for them, so there needs to be a logical
way to mark the dates as null within the code to translate this to the
database.

Personally, I usually create a struct that contains a date and a Boolean
called "IsNull" and just check that value before using the date. Then check
it when updating the db.

-> -----Original Message-----
-> From: Tim Musschoot [mailto:Click here to reveal e-mail address]
->
-> Whey convert it to NULL. This is not a valid timestamp...
->
-> I use this code:
->
-> DateTime cvDate;
-> try{
->     cvDate = DateTime.Parse(textbox.Text);
-> }
-> catch
-> {
->     cvDate = DateTime.Now;
-> }
->
-> This assurs you ALWAYS have a legal datetime value. You can use a
-> boolean to mark the usefullness of the date.... :
->
-> DateTime cvDate;
-> bool b_cvDate;
-> try{
->     cvDate = DateTime.Parse(textbox.Text);
->     b_cvDate = true;
-> }
-> catch
-> {
->     cvDate = DateTime.Now;
->     b_cvDate = false;
-> }
->
-> -----Oorspronkelijk bericht-----
-> Van: Brian W. Spolarich [mailto:Click here to reveal e-mail address]
->
-> This is sort of a problem in the .NET framework: how to represent
-> an uninitialized or null valued DateTime.
->
-> See
-> http://discuss.develop.com/archives/wa.exe?S2=dotnet&L=DOTNET&q=&s=da
-> teti
-> me+null&f=&a=&b=
->
-> for a discussion on this topic.
->
-> Regards,
->
-> -bws
->
->     -----Original Message-----
->     From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
->
->     Hi,
->
->     I'm using Convert.ToDateTime to convert a string representation of a

-> date in a TextBox. Here is what I'm doing:
->
->     DateTime cvDate;
->     cvDate = Convert.ToDateTime(textbox.Text);
->
->     This works fine if there is data in the text box, but fails if there

-> is not data in the text. So I want to check for the presence of data
-> in the text box before I do the conversion. So I check for the
-> length of the textbox value and perform the conversion if it contains
-> text.
->
->     if (textbox.Text.Length !=0)
->      cvDate = Convert.ToDateTime(textBox.Text);
->     else
->      I want to set cvDate to null. How do I do that? I get an
-> error when I do
->
->      cvDate = null;
->
->     Thanks
->     S

---
[This E-mail scanned for viruses by Declude Virus]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Stephen Rees
Try using SqlDateTime type (... courtesy of the developer list)

Steve.
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: 06 July 2002 23:51
To: aspngcs
Subject: [aspngcs] Convert.ToDateTime

Hi,

I'm using Convert.ToDateTime to convert a string representation of a date
in a TextBox. Here is what I'm doing:

DateTime cvDate;
cvDate = Convert.ToDateTime(textbox.Text);

This works fine if there is data in the text box, but fails if there is
not data in the text. So I want to check for the presence of data in the
text box before I do the conversion. So I check for the length of the
textbox value and perform the conversion if it contains text.

if (textbox.Text.Length !=0)
cvDate = Convert.ToDateTime(textBox.Text);
else
I want to set cvDate to null. How do I do that? I get an error
when I do

cvDate = null;

Thanks
S

DateTime. It works | [aspngcs] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT
Reply to this message...
 
    
SNegussie@aol.com
I'm having problems using SqlDateTime and DBNull. Here is what I'm doing:

SqlDateTime sdate;

if (textbx1.Text.Length !=0)
sdate = Convert.ToDateTime(textbx1.Text)
else
sdate = DBNull.Value;

I'm getting "Cannot implicity convert type System.DBNull to
System.Data.SqlTypes.SqlDateTime".

Here are my questions:
1) How can I set sdate to null using SqlDateTime types?
2) Is the statement in my if stmt correct? I'm assigning a SqlDateTime var
(sdate) the value of a txtbox after converting it using Convert.ToDateTime
which I think will result in System.DateTime value?

Thanks
Reply to this message...
 
    
SNegussie@aol.com
In a message dated 7/10/2002 12:28:23 PM Eastern Daylight Time,
Click here to reveal e-mail address writes:

[Original message clipped]

Any help on this?

Thanks
S
Reply to this message...
 
    
Ryan Trudelle-Schwarz
Try this:

if(textbx1.Text.Length != 0)
sdate = Convert.ToDateTime(textbx1.Text);
else
sdate = System.Data.SqlTypes.SqlDateTime.Null;

Note that it is using SqlDateTime's Null property to get a null value.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]

In a message dated 7/10/2002 12:28:23 PM Eastern Daylight Time,
Click here to reveal e-mail address writes:

I'm having problems using SqlDateTime and DBNull. Here is what I'm
doing:

SqlDateTime sdate;

if (textbx1.Text.Length !=0)
sdate = Convert.ToDateTime(textbx1.Text)
else
sdate = DBNull.Value;

I'm getting "Cannot implicity convert type System.DBNull to
System.Data.SqlTypes.SqlDateTime".

Here are my questions:
1) How can I set sdate to null using SqlDateTime types?
2) Is the statement in my if stmt correct? I'm assigning a SqlDateTime
var (sdate) the value of a txtbox after converting it using
Convert.ToDateTime which I think will result in System.DateTime value?

Any help on this?

Thanks
S

---
[This E-mail scanned for viruses by Declude Virus]

Reply to this message...
 
    
Werner Schram
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_001_01C22974.17EBF500"

------_=_NextPart_001_01C22974.17EBF500
Content-Type: text/plain

Hi,

SqlDateTime has a lot of constants and conversions:

1) sdate=SqlDateTime.Null
2) Yes, this statement is correct; SqlDateTime has an overloaded
conversion operator for both SqlDateTime to DateTime and DateTime to
SqlDateTime.

I hope this helps.

Werner.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: donderdag 11 juli 2002 13:55
To: aspngcs
Subject: [aspngcs] RE: Convert.ToDateTime

In a message dated 7/10/2002 12:28:23 PM Eastern Daylight Time,
Click here to reveal e-mail address writes:

I'm having problems using SqlDateTime and DBNull. Here is what I'm doing:

SqlDateTime sdate;

if (textbx1.Text.Length !=0)
sdate = Convert.ToDateTime(textbx1.Text)
else
sdate = DBNull.Value;

I'm getting "Cannot implicity convert type System.DBNull to
System.Data.SqlTypes.SqlDateTime".

Here are my questions:
1) How can I set sdate to null using SqlDateTime types?
2) Is the statement in my if stmt correct? I'm assigning a SqlDateTime var
(sdate) the value of a txtbox after converting it using Convert.ToDateTime
which I think will result in System.DateTime value?

Any help on this?

Thanks
S | [aspngcs] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

------_=_NextPart_001_01C22974.17EBF500
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40";>

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">

<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:Click here to reveal e-mail address2A50">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:DoNotRelyOnCSS/>
</o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:DocumentKind>DocumentEmail</w:DocumentKind>
<w:EnvelopeVis/>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
    {font-family:Tahoma;
    panose-1:2 11 6 4 3 5 4 4 2 4;
    mso-font-charset:0;
    mso-generic-font-family:swiss;
    mso-font-pitch:variable;
    mso-font-signature:553679495 -2147483648 8 0 66047 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {mso-style-parent:"";
    margin:0cm;
    margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:12.0pt;
    font-family:"Times New Roman";
    mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
    {color:blue;
    text-decoration:underline;
    text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
    {color:purple;
    text-decoration:underline;
    text-underline:single;}
span.EmailStyle17
    {mso-style-type:personal-reply;
    mso-style-noshow:yes;
    mso-ansi-font-size:10.0pt;
    mso-bidi-font-size:10.0pt;
    font-family:Arial;
    mso-ascii-font-family:Arial;
    mso-hansi-font-family:Arial;
    mso-bidi-font-family:Arial;
    color:navy;}
span.SpellE
    {mso-style-name:"";
    mso-spl-e:yes;}
span.GramE
    {mso-style-name:"";
    mso-gram-e:yes;}
@page Section1
    {size:21.0cm 842.0pt;
    margin:3.0cm 42.55pt 64.9pt 70.6pt;
    mso-header-margin:22.95pt;
    mso-footer-margin:17.3pt;
    mso-paper-source:0;}
div.Section1
    {page:Section1;}
/* List Definitions */
@list l0
    {mso-list-id:579944100;
    mso-list-type:hybrid;
    mso-list-template-ids:887144214 67698705 67698713 67698715 67698703 =
67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
    {mso-level-text:"%1\)";
    mso-level-tab-stop:36.0pt;
    mso-level-number-position:left;
    text-indent:-18.0pt;}
ol
    {margin-bottom:0cm;}
ul
    {margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */=20
table.MsoNormalTable
    {mso-style-name:"Table Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-parent:"";
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-para-margin:0cm;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:10.0pt;
    font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:36.0pt'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Hi,<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>=

<p class=3DMsoNormal><span class=3DSpellE><font size=3D2 color=3Dnavy =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;color:navy'>SqlDateTime</spa=
n></font></span><font
size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'> has a lot of constants and =
conversions:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>=

<p class=3DMsoNormal =
style=3D'margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 =
lfo1;
tab-stops:list 36.0pt'><![if !supportLists]><font size=3D2 color=3Dnavy =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;mso-fareast-font-family:Aria=
l;
color:navy'><span style=3D'mso-list:Ignore'>1)<font size=3D1 =
face=3D"Times New Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>       =
</span></font></span></span></font><![endif]><span
class=3DSpellE><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial;color:navy'>sdate</span></font></span><font size=3D2
color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>=3D<span =
class=3DSpellE>SqlDateTime.Null</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal =
style=3D'margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 =
lfo1;
tab-stops:list 36.0pt'><![if !supportLists]><font size=3D2 color=3Dnavy =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial;mso-fareast-font-family:Aria=
l;
color:navy'><span style=3D'mso-list:Ignore'>2)<font size=3D1 =
face=3D"Times New Roman"><span
style=3D'font:7.0pt "Times New =
Roman"'>       =
</span></font></span></span></font><![endif]><font
size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>Yes, this statement is correct; <span =
class=3DSpellE>SqlDateTime</span>
has an overloaded conversion operator for both <span =
class=3DSpellE>SqlDateTime</span>
to <span class=3DSpellE>DateTime</span> and <span =
class=3DSpellE>DateTime</span> to
<span class=3DSpellE>SqlDateTime</span>.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>=

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>I hope this =
helps.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>=

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Werner.<o:p></o:p></span></font></p=
>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>=

<p class=3DMsoNormal style=3D'margin-left:36.0pt'><font size=3D2 =
face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original =
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> Click here to reveal e-mail address
[mailto:Click here to reveal e-mail address] <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> donderdag 11 juli =
2002 13:55<br>
<b><span style=3D'font-weight:bold'>To:</span></b> aspngcs<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> [aspngcs] RE:
Convert.ToDateTime</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:36.0pt'><font size=3D3
face=3D"Times New Roman"><span =
style=3D'font-size:12.0pt'><o:p> </o:p></span></font></p>

<p class=3DMsoNormal style=3D'margin-left:36.0pt'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>In a message dated =
7/10/2002
12:28:23 PM Eastern Daylight Time, Click here to reveal e-mail address writes: <br>
<br>
<br style=3D'mso-special-character:line-break'>
<![if !supportLineBreakNewLine]><br =
style=3D'mso-special-character:line-break'>
<![endif]><o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'margin-left:36.0pt'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>I'm having problems using
SqlDateTime and DBNull.  Here is what I'm doing: <br>
<br>
SqlDateTime sdate; <br>
<br>
if (textbx1.Text.Length !=3D0) <br>
     sdate =3D =
 Convert.ToDateTime(textbx1.Text) <br>
else <br>
     sdate =3D DBNull.Value; <br>
<br>
I'm getting "Cannot implicity convert type System.DBNull to
System.Data.SqlTypes.SqlDateTime". <br>
<br>
Here are my questions: <br>
1)  How can I set sdate to null using SqlDateTime types? <br>
2)  Is the statement in my if stmt correct? I'm assigning a =
SqlDateTime
var (sdate) the value of a txtbox after converting it using =
Convert.ToDateTime
which I think will result in System.DateTime value? =
<o:p></o:p></span></font></p>

<p class=3DMsoNormal style=3D'margin-left:36.0pt'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'><br>
<br>
Any help on this? <br>
<br>
Thanks <br>
S</span></font><font face=3DArial><span style=3D'font-family:Arial'> | =
[aspngcs]
member Click here to reveal e-mail address =3D YOUR ID |
http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT =
</span></font><o:p></o:p></p>

</div>

</body>

</html>

------_=_NextPart_001_01C22974.17EBF500--

--------------InterScan_NT_MIME_Boundary--

Reply to this message...
 
    
Ariff Damji
According to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconvertclasstodatetimetopic13.asp

Convert.ToDateTime(string) will take a null string and convert it to DateTime.MinValue. Seems like this is the way to go...

Ariff

--------------------------------
From: Ariff Damji
Reply to this message...
 
 
System.Convert
System.Data.SqlTypes.SqlDateTime
System.DateTime
System.DBNull
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.TextBox




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification