-1

当我尝试更新我的表时出现错误

这是代码

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

这就是错误

Primera excepción del Tipo 'System.Data.SqlClient.SqlException' en System.Data.dll

英语

System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的第一个异常

4

1 回答 1

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)
于 2013-07-15T02:22:12.570 回答