I am trying to convert a MySQL time to a string using VB.NET.
Dim adpt As New MySqlDataAdapter(dbcmdstring, connection)
Dim myDataTable As New DataTable()
adpt.Fill(myDataTable)
DataGridView1.DataSource = myDataTable
DataGridView1.Columns.Remove("ActivityID")
DataGridView1.Columns.Remove("ActivityDate")
DataGridView1.Columns.Remove("UserID")
DataGridView1.Columns(0).HeaderCell.Value = "Name"
DataGridView1.Columns(1).HeaderCell.Value = "Start Time"
DataGridView1.Columns(2).HeaderCell.Value = "End Time"
DataGridView1.Columns.Add("Duration", "Duration")
DataGridView1.RowHeadersVisible = False
Dim duration As New TimeSpan
Dim durationStr As String = ""
Dim i As Integer = 0
For Each row As DataGridViewRow In DataGridView1.Rows
duration = Date.Parse(row.Cells(2).Value.ToString).Subtract(Date.Parse(row.Cells(1).Value.ToString))
durationStr = Math.Round(duration.TotalMinutes).ToString & ":" & Math.Round(duration.TotalSeconds).ToString
row.Cells(3).Value = durationStr
Next
When the date is parsed during the construction of the duration variable, it throws an error:
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplicationSQL.exe
Additional information: Object reference not set to an instance of an object.
I can successfully parse the date and show it in a messagebox, but not convert it to a useable string. I have also tried using just the .value of the time as well.
Any help?