how can I troubleshoot "Object cannot be cast from DBNull to other types."? I am using a combobox, to retrieve the price and discount price of the service, If I select an item in combobox3 once, error will not occur, but if I select a item again in combobox3, "Object cannot be cast from DBNull to other types." will occur..
here is my code
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim ds As New DataSet
ds = getPrice(arr(ComboBox2.SelectedIndex), ComboBox3.Text)
If ds.Tables("getPrice").Rows.Count > 0 Then
For i As Integer = 0 To ds.Tables("getPrice").Rows.Count - 1
TextBox1.Text = Convert.ToDecimal(ds.Tables("getPrice").Rows(i).Item(0))
TextBox2.Text = Convert.ToDecimal(ds.Tables("getPrice").Rows(i).Item(1))
Next
End If
End Sub
this is my query
Public Function getPrice(ByVal serviceId As String, ByVal breedSize As String)
If breedSize = "Small Breed" Then
sqlStr = "Select price_small_breed, discount_small_breed From tblServicePrice Where service_id = " + serviceId + ""
ElseIf breedSize = "Medium Breed" Then
sqlStr = "Select price_medium_breed, discount_medium_breed From tblServicePrice Where service_id = " + serviceId + ""
ElseIf breedSize = "Big Breed" Then
sqlStr = "Select price_big_breed, discount_big_breed From tblServicePrice Where service_id = " + serviceId + ""
End If
ds.Clear()
da = New OleDbDataAdapter(sqlStr, con.ConnectionString)
da.Fill(ds, "getPrice")
Return ds
End Function
here is the image
what could be the caused of having this problem?