当我尝试更新我的表时出现错误
这是代码
Private Sub babonar_Click(sender As Object, e As EventArgs) Handles babonar.Click
Dim saldo As Decimal
Dim abonar As Double = 0
Dim cedula As String
Dim abono As New ClaseAbono
saldo = Convert.ToDecimal(ttsaldo.Text)
abonar = Convert.ToDouble(ttabonar.Text)
cedula = ttcecula.Text
abono.Nombre = ttnombre.Text
abono.Saldo = saldo
abono.Cedula = cedula
abono.Abonar = abonar
abono.Abono()
End Sub
这是班级的代码
Public Function Abono()
Dim vcedula As String = ""
Dim retur As Boolean
Dim saldoo As Double = 0
saldoo = xsaldo - xabonar
Dim sql As String = "update Cliente set Abono = @Abonar, Saldo = @saldoo where Cedula = @Cedula"
Using conn As New SqlConnection(sCon)
Dim command As New SqlCommand(sql, conn)
Try
command.Parameters.AddWithValue("Abono", xabonar)
command.Parameters.AddWithValue("Saldo", saldoo)
conn.Open()
command.ExecuteNonQuery()
Catch ex As SqlException
Console.WriteLine("Error actualizando datos ")
End Try
End Using
Return retur
End Function
这是错误
Primeraexpepcióndeltipo'System.Data.SqlClient.SqlException'en System.Data.dll
英
System.Data.dll中出现'System.Data.SqlClient.SqlException'类型的第一个异常
答案 0 :(得分:1)
例外不是很有用。但是,存在一些潜在的问题。 sql命令参数需要@
符号。此外,您还需要添加cedula
参数。
换句话说,这段代码:
command.Parameters.AddWithValue("Abono", xabonar)
command.Parameters.AddWithValue("Saldo", saldoo)
应改为:
command.Parameters.AddWithValue("@Abono", xabonar)
command.Parameters.AddWithValue("@Saldo", saldoo)
' you will need to substitute your correct variable for the `cedula` variable here '
command.Parameters.AddWithValue("@Cedula", cedula)