Dates Problem
-
I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca
-
I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca
When the user does not enter a value, retrieving the
Text
property returns an empty string. You are attempting to perform an implicit conversion of""
to a date, which is not possible. You'll need to guard against this by testing to ensure that there is a value in the textbox before converting, or by usingDateTime.TryParse
. Hope that helps. :)--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
-
I have a Search Page which contains dates and text fields. When I leave the Date fields blank an error is thrown in my code stating that cannot "Conversion from String to type Date is not valid". This happens because I am trying to assign the empty Date Text field to A Variable of type Date. If the Date Text field contains a Date there is no error thrown. Dim dtDateFrom As Date Dim dtDateTo As Date dtDateFrom = tbxDtFrom.Text dtDateTo = tbxDtTo.Text Anyone any ideas why this is happening macca