Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cast from type DBNull error

Status
Not open for further replies.

CHMS2013

IS-IT--Management
Jun 5, 2013
5
0
0
US
Good morning.

I am trying to set a field operations schedule that's tied to our SQLServer and when I refresh the schedule I am receiving an error "Error: Cast from type 'DBNull' to type 'Date' is not valid", I have a bunch of jobs that have disappeared off of today's schedule as if they've been closed out but they have not been. When I run a schedule report on paper the jobs show up but not on my interface I use.

This program was fully functional with zero errors yesterday afternoon when I left, now I'm being thrown this error and have zero clue how to fix.
 
The error message you are getting is not a SQL Server error message. It sounds to me like a .net error message instead.

This error occurs when a null is returned for a column, but you don't check for nulls, you just try to assign it to a date variable.

Do you know what query is actually being executed against the database engine when this error occurs?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I honestly don't know. I can open my installer schedule just fine, when I try to open Templ/Inst or just Templ is when I receive the errors. I was told to look for a temp or inst that has a null date, "Query would look something like this: Select * From Events where Event IN(‘Template’,’Install’) and Date Is Null "....I honestly don't even know where to begin, I'm VERY new at all of this.
 
gmmastros is correct, this is a ADO.Net error. Basically you are selecting data from a table but that table data has a NULL in a date column. Probably coming out of the database with a datareader into the app? When a null comes from the database into the application .Net converts it to DBNull but it then needs to be converted to a datetime

e.g
Code:
if(myfield == DBNull.Value) 
  myVar = DateTime.Min 
else
  myVar = myfield;

If you could post some code that would help?

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top