Click to See Complete Forum and Search --> : Error converting datatype varchar to numeric


dr223
February 23rd, 2009, 08:21 AM
Hallo,
I am working with SQL and Vb.net. When I run the following function (shown below) an error is highlighted "Error converting varchar to numeric". Whats wrong with the coding that triggers the error..


Dim query As String
Dim cmd As New SqlCommand
Dim irow As Integer

For irow = 0 To DgvToPay.Rows.Count - 1
If DgvToPay.Rows(irow).Cells(3).Value = True Then

Try
query = "INSERT INTO xyz.TblQuarPay (prac_no, prac_eid, num_pats, ToPay,
AmounttobePaid) VALUES ('" & _
DgvToPay.Rows(irow).Cells(0).Value & "', '" & _
DgvToPay.Rows(irow).Cells(1).Value & "', '" & _
DgvToPay.Rows(irow).Cells(2).Value & "', '" & _
"Yes" & "', '" & _
DgvToPay.Rows(irow).Cells(4).Value & "')"
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Payment System")
End Try
End If
Next irow
End Sub



Thanks

Shuja Ali
February 23rd, 2009, 01:01 PM
It looks like one of your fields is numeric and you are trying to insert a string into it. Put a break point on the cmd.ExecuteNonQuery() line and check what the query looks like in the Watch window. You need to make sure that you are not inserting a varchar value into a numeric column.