I am trying (much too long) to convert a DateTime column to a label.Text.
Various errors:
What am I missing?
drExpDatesRow = dtAllCompanies.Select("CompanyID = " + CompanyID.ToString())
Dim ls_ExpiresDateString As String
If (Not IsDBNull(drExpDatesRow("Expdate"))) Then
Date.TryParse(drExpDatesRow("Expdate").ToString(), ls_ExpiresDateString)
'ls_ExpiresDateString = ldt_ExpiresDate.ToString("MM/dd/yyyy")
lbl_ExpireDate.Text = ls_ExpiresDateString.ToString()
Else
lbl_ExpireDate.Text = ""
End If
System.InvalidCastException was unhandled Message=Conversion from string "Expdate" to type 'Integer' is not valid.
Source=Microsoft.VisualBasic StackTrace: at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at zzz.winCompanyInfo.CompanyInfo_Load(Object sender, EventArgs e) in C:\inetpub\zzz.vb:line 638 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException: System.FormatException Message=Input string was not in a correct format. Source=Microsoft.VisualBasic StackTrace: at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) InnerException:
UPDATE** Added DataRow logic
TryParse
is definedTryParse(ByVal Object, ByRef Date)
so ls_ExpiresDateString should be aDate
not aString
. Btw, a variable declared as aString
will never be anything other than aString
. So there is no need to callToString
for aString
. – Bjørn-Roger KringsjådrExpDatesRow = dtAllCompanies.Select("CompanyID = " + CompanyID.ToString())
returns array of rows. So you need to doIsDBNull(drExpDatesRow(0)("Expdate"))
. But also check the length of array first - may be there nothing found – T.S.