I'm trying to load sum of columns to text boxes. but it give me this error:
"Object cannot be cast from DBNULL to other types"
this is code :
query = "SELECT sum(fuel) as ttlfuel, sum(stationery) as ttlstationery, sum(salary) as ttlsalary, sum(vehicle_part) as ttlvp, sum(other) as ttlother FROM mcs.expenses WHERE datee BETWEEN '" & dtpisf.Value & "' AND '" & dtpist.Value & "'"
Dim cmd = New MySqlCommand(query, con)
Dim dr As MySqlDataReader
Try
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
Me.txtfuel.Text = Convert.ToDecimal(dr("ttlfuel"))
Me.txtstationary.Text = Convert.ToDecimal(dr("ttlstationery"))
Me.txtcollectorsalery.Text = Convert.ToDecimal(dr("ttlsalary"))
Me.txtvehiclepart.Text = Convert.ToDecimal(dr("ttlvp"))
Me.txtotherexpenses.Text = Convert.ToDecimal(dr("ttlother"))
End While
dr.Close()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
Try
If (con.State = ConnectionState.Open) Then
con.Close()
End If
Catch ex2 As Exception
MsgBox(ex2.Message)
End Try
End Try