CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    192

    Error converting datatype varchar to numeric

    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

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Error converting datatype varchar to numeric

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured