I have this line of code which gets the activation date of an agent and computes the difference between date.now to get the date difference:
Dim dt As New DataTable
dt = ExecQuery("select agtid,Activation from tblagentinfo")
If dt.Rows.Count > 0 Then
Dim activation As String
For i As Integer = 0 To dt.Rows.Count - 1
Dim a As Date
Dim b As Date
a = dt.Rows(i)(1).ToString
b = Date.Now
activation = DateDiff(DateInterval.Day, a, b)
If activation >= 365 Then
ExecQuery("Update tblagentinfo set AgentStat = 'Inactive' where agtid = '" & dt.Rows(i)(0).ToString & "'")
End If
Next
dt = ExecQuery("select AgentStat from tblagentinfo where AgentStat = 'Inactive'")
MsgBox(dt.Rows.Count.ToString + " Inactive Agents to Follow up")
End If
When I try to run it, it always gives me this error message:
Conversion from string "" to type 'Date' is not valid.
and highlights this part:
a = dt.Rows(i)(1).ToString
I have already tried using DateParseExact and CDate but it still returns that error message. What's wrong with the code? Why the error message?