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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error validating empty/null date field

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I am trying to validate a date field from a sql server DB, and Ii is raising error - "Conversion from string "" to type 'Date' is not valid" or
Conversion from DBNull to type 'Date' is not valid". Validation is for loading a datagridview with datatable thru a BindingSource.

Here is my date field validation code

IIf(bsRow.Item("TermDate") IsNot DBNull.Value AndAlso Not (Trim(bsRow.Item("TermDate").ToString) = ""), CDate(bsRow.Item("Cobra Termination Date").ToString("MM/dd/yyyy"), "NULL")

I have tried different validation ie. string.isemptyornull(), isnothing(), bsRow.Item("Termination Date").ToString = "NULL"

Any help will be greatly appreciated.
 
Pls. disregard this thread. I decided to load the grid thru .datasource property and was able to format the date fields.
I was looping thru datasource before.
 
Just for future reference, instead of using "IsNot DBNull.Value", you would use "Not IsDBNull(bsRow.Item("TermDate"))".

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top