我想为之前有值的字段添加值。 我的代码是:
Dim Credits As Integer = Int64.Parse(FinalPay.ToString)
Dim cmd As New SqlCommand("Update Users Set Credit=Credit+" + Credits +
" Where Email ='" + UserEmail + "'", con)
但我收到的错误是:
“从字符串转换为double无效”
答案 0 :(得分:3)
如果使用SQL参数,它应该可以正常工作:
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})
调整每个参数类型(和大小)以匹配数据库中的声明。
答案 1 :(得分:-2)
Dim Credits As Integer = Int64.Parse(FinalPay.ToString)
Dim cmd As New SqlCommand("Update Users Set Credit=Credit+" & Credits &
" Where Email ='" & UserEmail & "'", con)
如果你想在vb中连接一个字符串,你想使用“&”操作