Click here to Skip to main content
15,899,632 members
Home / Discussions / C#
   

C#

 
QuestionWindow Form repaint problem Pin
ppp00119-Oct-05 23:56
ppp00119-Oct-05 23:56 
Questionc# modem communication Pin
Anil Ch19-Oct-05 23:51
Anil Ch19-Oct-05 23:51 
AnswerRe: c# modem communication Pin
javad asadi17-Jan-12 18:35
javad asadi17-Jan-12 18:35 
QuestionDBNull.Value to string Pin
Brendan Vogt19-Oct-05 23:43
Brendan Vogt19-Oct-05 23:43 
AnswerRe: DBNull.Value to string Pin
ZainAMJ20-Oct-05 0:11
ZainAMJ20-Oct-05 0:11 
GeneralRe: DBNull.Value to string Pin
Brendan Vogt20-Oct-05 0:40
Brendan Vogt20-Oct-05 0:40 
GeneralRe: DBNull.Value to string Pin
ZainAMJ20-Oct-05 0:48
ZainAMJ20-Oct-05 0:48 
GeneralRe: DBNull.Value to string Pin
Brendan Vogt20-Oct-05 1:06
Brendan Vogt20-Oct-05 1:06 
If I were to convert a null value coming from a database to something else, would this be good enough? I do not know to what date I should convert if it contains no values, so I chose 1900/01/01. Any ideas?

public static DateTime CheckDateForDBNulls(DateTime dtCheckDate)
{
if(Convert.IsDBNull(dtCheckDate))
return Convert.ToDateTime("1900/01/01");
else
return Convert.ToDateTime(dtCheckDate);
}

Calling function is:

objCustomer.StartDate = Globals.CheckDateForDBNulls(Convert.ToDateTime(objDr["StartDate"])); // Check for DBNull value

I get a horrible error:


Object cannot be cast from DBNull to other types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Please can you help again. Cool | :cool:

-- modified at 7:06 Thursday 20th October, 2005
GeneralRe: DBNull.Value to string Pin
ZainAMJ20-Oct-05 17:07
ZainAMJ20-Oct-05 17:07 
GeneralRe: DBNull.Value to string (Error In That Code) Pin
ZainAMJ20-Oct-05 17:10
ZainAMJ20-Oct-05 17:10 
AnswerRe: DBNull.Value to string Pin
Guffa20-Oct-05 1:31
Guffa20-Oct-05 1:31 
QuestionString conversion to DBNull.Value Pin
Brendan Vogt19-Oct-05 23:35
Brendan Vogt19-Oct-05 23:35 
AnswerRe: String conversion to DBNull.Value Pin
Dead Skin Mask20-Oct-05 0:13
Dead Skin Mask20-Oct-05 0:13 
GeneralRe: String conversion to DBNull.Value Pin
Brendan Vogt20-Oct-05 0:40
Brendan Vogt20-Oct-05 0:40 
GeneralRe: String conversion to DBNull.Value Pin
Dead Skin Mask20-Oct-05 1:28
Dead Skin Mask20-Oct-05 1:28 
GeneralRe: String conversion to DBNull.Value Pin
Brendan Vogt20-Oct-05 2:16
Brendan Vogt20-Oct-05 2:16 
QuestionAudioVideoPlayback: Video as texture. Unable to Dispose() Pin
Pixinger7719-Oct-05 23:15
Pixinger7719-Oct-05 23:15 
QuestionXML File encryption Pin
rmedo19-Oct-05 22:49
rmedo19-Oct-05 22:49 
AnswerRe: XML File encryption Pin
Guffa19-Oct-05 23:35
Guffa19-Oct-05 23:35 
GeneralRe: XML File encryption Pin
rmedo23-Oct-05 2:03
rmedo23-Oct-05 2:03 
GeneralRe: XML File encryption Pin
Guffa24-Oct-05 21:24
Guffa24-Oct-05 21:24 
GeneralRe: XML File encryption Pin
rmedo24-Oct-05 22:53
rmedo24-Oct-05 22:53 
QuestionRegarding Resolving IP Address Pin
A.Grover19-Oct-05 21:19
A.Grover19-Oct-05 21:19 
AnswerRe: Regarding Resolving IP Address Pin
leppie19-Oct-05 22:38
leppie19-Oct-05 22:38 
GeneralRe: Regarding Resolving IP Address Pin
A.Grover19-Oct-05 23:03
A.Grover19-Oct-05 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.