[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 670
  • Last Modified:

"Conversion from string "" to type 'Date' is not valid." in vb.net

I am getting the error "Conversion from string "" to type 'Date' is not valid." from the following line of code:

If oSheet.Cells(i, 6).value = "" Then Exit For

What I am doing is adding values from excel into a CheckedListbox. The values are dates, and the line above is just to check to make sure that the excel cell is not blank. It worked fine for stings and values, but dates it is getting hung up on. Any ideas how to fix this?
0
tiehaze
Asked:
tiehaze
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If oSheet.Cells(i, 6).value.ToString() = "" Then Exit For
0
 
tiehazeAuthor Commented:
I am getting the following error now:

System.NullReferenceException
{"Object reference not set to an instance of an object."}
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
but I guess not for the same cell/line?
please specify
0
 
tiehazeAuthor Commented:
no... I am adding dates from an excel spreadsheet to a checkedlistbox. I need to check if the cell is blank, and if it is, I used the Exit For statement.

Like I said, it works when the data is strings or numbers, but dates are not working.
0
 
Wayne Taylor (webtubbs)Commented:
Hi tiehaze,

Try perhaps using the Text property....

    If oSheet.Cells(i, 6).Text = "" Then Exit For

Regards,

Wayne
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now