Conversion from String to type Double is not valid

winsonlee

Member
Joined
Jan 5, 2008
Messages
10
Programming Experience
Beginner
qty is define as double and when i tried to execute the following code, it still gives me an error message saying Conversion from string "Update PadFile SET soh =" to type 'Double' is not valid. Which part of the code went wrong ?

VB.NET:
    Private Sub updateQuantity(ByVal stockType As String, ByVal dateStart As String, ByVal apnnumber As String, ByVal storeNo As String, ByVal qty As Double)
        cmd.Connection = conn
        conn.Open()

            cmd.CommandText = "UPDATE PadFile SET soh = " + qty + " WHERE date = '" + dateStart + "' AND apn = '" + apnnumber + "' AND store = '" + storeNo + "'"
            If (cmd.ExecuteNonQuery() = 0) Then
                cmd.CommandText = "INSERT INTO PadFile(date, apn, store, soh) VALUES('" + dateStart + "','" + apnnumber + "','" + storeNo + "'," + qty + ")"
                cmd.ExecuteNonQuery()
            End If

        conn.Close()

    End Sub
 
You have to use parameters, see for example this post.

In the above code you also use the wrong operator for concenating string, + is wrong, & is correct.
 
Back
Top