Reputation: 63
I want to add a value to a field that has value from before. My code is:
Dim Credits As Integer = Int64.Parse(FinalPay.ToString)
Dim cmd As New SqlCommand("Update Users Set Credit=Credit+" + Credits +
" Where Email ='" + UserEmail + "'", con)
But I get an error that says:
"Conversion from string to double is not valid"
Upvotes: 1
Views: 2414
Reputation: 244
Dim Credits As Integer = Int64.Parse(FinalPay.ToString)
Dim cmd As New SqlCommand("Update Users Set Credit=Credit+" & Credits &
" Where Email ='" & UserEmail & "'", con)
When you want to concat a string in vb you want to use the "&" operator
Upvotes: -2
Reputation: 25013
If you use SQL parameters it should work correctly:
Dim cmd As New SqlCommand("UPDATE Users SET Credit = Credit + @Credits Where Email = @Email", con)
cmd.Parameters.Add(New SqlParameter With {.ParameterName = "@Credits", .SqlDbType = SqlDbType.Int, .Value = finalPay})
cmd.Parameters.Add(New SqlParameter With {.ParameterName = "@Email", .SqlDbType = SqlDbType.NVarChar, .Size = 256, .Value = userEmail})
Adjust each parameter type (and size) to match the declarations in the database.
Upvotes: 3