0

mi pregunta es como resolver este error La conversión de la cadena "update xcobrar set monto = " en el tipo 'Double' no es válida. He tratado cambiando los valores de double a string, y me da error al tratar de convertir la cadena lin de la consulta, em el evento button2 click, en la lien lin=update....

Public Class Cobros

Private Sub Cobros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    comboapto()
    llenacombo()
    combobanco()
    DataGridView1.DefaultCellStyle.Font = New Font("Microsoft Sans Serif", 12)
    'cargar numero de control
    Dim cmd7 As OleDbCommand = con.CreateCommand()
    cmd7.CommandText = "select control from nrocontrol"
    Dim suma5 As String = Convert.ToString(cmd7.ExecuteScalar)
    Label4.Text = suma5
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dispose()
    MPpal.MenuStrip1.Enabled = True
    MPpal.Panel1.Visible = False
End Sub
Sub llenacombo()
    Dim Sql As String = "select tipo from formapago"
    Dim Dt As New DataTable
    Dim Da As New OleDbDataAdapter(Sql, con)
    Da.Fill(Dt)
    ComboBox2.DataSource = Dt
    ComboBox2.DisplayMember = "tipo"
    ComboBox2.SelectedIndex = -1
End Sub
Sub combobanco()
    Dim Dt As New DataTable
    Dim sql2 As String = "select banco from bancos order by banco ASC"
    Dim Da As New OleDbDataAdapter(sql2, con)
    Da.Fill(Dt)
    ComboBox3.DataSource = Dt
    ComboBox3.DisplayMember = "banco"
    ComboBox3.SelectedIndex = -1
End Sub
Sub comboapto()
    Dim Dt As New DataTable
    Dim sql2 As String = "select apto from xcobrar order by apto ASC"
    Dim Da As New OleDbDataAdapter(sql2, con)
    Da.Fill(Dt)
    ComboBox1.DataSource = Dt
    ComboBox1.DisplayMember = "apto"
    ComboBox1.SelectedIndex = -1
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim apto As String = ComboBox1.Text
    If ComboBox1.Text = "System.Data.DataRowView" Then
        Exit Sub
    End If
    If ComboBox1.Text = "" Then
        DataGridView1.DataSource = Nothing
        DataGridView2.DataSource = Nothing
        DataGridView1.Rows.Clear()
        DataGridView2.Rows.Clear()
        DataGridView1.Refresh()
        DataGridView2.Refresh()
        Label2.Text = ""
        Label12.Text = ""
        Label13.Text = ""
    End If
    Dim cmd As OleDbCommand = con.CreateCommand()
    cmd.CommandText = "select nombres from propietarios where apto   = '" + apto + "'"
    Dim dr As OleDbDataReader = cmd.ExecuteReader
    If dr.Read() Then
        Label2.Text = Convert.ToString(dr("nombres"))
    End If
    'llenar el mesex pendientes
    Dim x As Integer = 0
    DataGridView1.Rows.Clear()
    DataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray
    DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue
    Dim cmd2 As OleDbCommand = con.CreateCommand()
    cmd2.CommandText = "select mes, monto, dolares, nromov from xcobrar where apto = '" + apto + "'"
    Dim dr2 As OleDbDataReader = cmd2.ExecuteReader
    Do While dr2.Read()
        DataGridView1.Rows.Add()
        DataGridView1(0, x).Value = Convert.ToString(dr2("Mes"))
        DataGridView1(1, x).Value = Convert.ToString(dr2("Monto"))
        DataGridView1.Columns("Column2").DefaultCellStyle.Format = "N2"
        DataGridView1(2, x).Value = Convert.ToString(dr2("Dolares"))
        DataGridView1.Columns("Column3").DefaultCellStyle.Format = "N2"
        DataGridView1(3, x).Value = Convert.ToString(dr2("nromov"))
        x = x + 1
    Loop
    DataGridView1.Columns(0).HeaderText = "Mes"
    DataGridView1.Columns(1).HeaderText = "Monto"
    DataGridView1.Columns(2).HeaderText = "Dolar"
    DataGridView1.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    DataGridView1.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
    'llenar historial
    Dim sql3 As String = "SELECT fecha, mes, monto, formapago , fechaoperacion, referencia, banco FROM historial WHERE apto = '" + apto + "'"
    Dim dt3 As New DataTable
    Dim da3 As New OleDbDataAdapter
    Dim command3 As New OleDbCommand(sql3, con)
    DataGridView2.Refresh()
    da3.SelectCommand = command3
    da3.Fill(dt3)
    If dt3.Rows.Count = 0 Then
        Exit Sub
    End If
    DataGridView2.DataSource = dt3
    DataGridView2.Columns(0).HeaderText = "Fecha"
    DataGridView2.Columns(1).HeaderText = "Mes"
    DataGridView2.Columns(2).HeaderText = "Monto"
    DataGridView2.Columns(3).HeaderText = "Forma Pago"
    DataGridView2.Columns(4).HeaderText = "Fecha Oper"
    DataGridView2.Columns(5).HeaderText = "Referencia"
    DataGridView2.Columns(6).HeaderText = "Banco"
    '  sumar totales
    Dim nro As Double
    Dim cmd6 As OleDbCommand = con.CreateCommand()
    cmd6.CommandText = "select sum (monto) from xcobrar where apto = '" + apto + "'"
    nro = Convert.ToDouble(cmd6.ExecuteScalar)
    Label12.Text = CDbl(nro).ToString("N2") + " BsS"
    Dim cmd7 As OleDbCommand = con.CreateCommand()
    cmd7.CommandText = "select sum (dolares) from xcobrar where apto = '" + apto + "'"
    nro = Convert.ToDouble(cmd7.ExecuteScalar)
    Label13.Text = CDbl(nro).ToString("N2") + " $"
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
    If Not (Char.IsControl(e.KeyChar) OrElse Char.IsDigit(e.KeyChar)) _

AndAlso (Not e.KeyChar = "," Or TextBox2.Text.Contains(",")) Then e.Handled = True End If End Sub Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress If Not (Char.IsControl(e.KeyChar) OrElse Char.IsDigit(e.KeyChar)) _ AndAlso (Not e.KeyChar = "," Or TextBox4.Text.Contains(",")) Then e.Handled = True End If End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    'verificar(datos)
    If ComboBox1.Text = "" Then
        MsgBox("Debe Seleccionar un apartamento")
        Exit Sub
    End If
    If ComboBox2.Text <> "Efectivo" And ComboBox2.Text <> "Divisa" Then
        If TextBox4.Text = "" Then
            MsgBox("Debe ingresar un monto")
            Exit Sub
        End If
        If TextBox1.Text = "" Then
            MsgBox("Debe igresar una referencia")
            Exit Sub
        End If
        If ComboBox3.Text = "" Then
            MsgBox("Debe Seleccionar un banco")
            Exit Sub

        End If
    End If
    'crear variables
    Dim fec As Date = Date.Now
    Dim apto As String = ComboBox1.Text
    Dim mes As String
    Dim forpag As String = ComboBox2.Text
    Dim fecope As String = DateTimePicker1.Value

    If ComboBox2.Text = "" Then
        MsgBox("Debe especificar la cotización")
        Exit Sub
    End If
    Dim lin As String
    Dim tas, deu, pag, monb, mond, dif, dol As Double
    tas = TextBox2.Text
    pag = TextBox4.Text
    'calcular el pago
    Dim a As Integer = 0
    Dim nro As String
    If DataGridView1.Rows.Count > 0 Then
        For Each Fila As DataGridViewRow In DataGridView1.Rows
            If Not Fila Is Nothing Then
                nro = DataGridView1(3, a).Value.ToString
                mes = DataGridView1(0, a).Value.ToString
                Dim sql10 As String = "SELECT monto, dolares from xcobrar WHERE nromov = " + nro
                Dim com10 As New OleDbCommand(sql10, con)
                Dim dr10 As OleDbDataReader = com10.ExecuteReader
                If dr10.Read() Then
                    deu = Convert.ToDouble(dr10("monto"))
                    dol = Convert.ToDouble(dr10("dolares"))
                End If
                If ComboBox2.Text = "Divisa" Then
                    mond = pag - dol
                    monb = tas * pag
                    dif = monb - deu
                    If mond < 0 Then
                        mond = mond * -1
                    End If
                    If monb < 0 Then
                        monb = monb * -1
                    End If
                    lin = "update xcobrar set monto = " + monb + ", dolares = " + mond + " where nromov = " + nro
                Else
                    mond = (pag / tas) - dol
                    monb = pag - deu
                    dif = monb - deu
                    If mond < 0 Then
                        mond = mond * -1
                    End If
                    If monb < 0 Then
                        monb = monb * -1
                    End If
                    lin = "update xcobrar set monto = " + monb + ", dolares = " + mond + " where nromov = " + nro
                End If
                If dif < 0 Then
                    'actualizar xcobrar
                    Dim sql7 As String = lin
                    Dim com7 As New OleDbCommand(sql7, con)
                    Dim dr7 As OleDbDataReader = com7.ExecuteReader
                    'actualizar historial


                End If




            End If
        Next
    End If

    'aumentar el numero de control
    nrocon()
End Sub

End Class

1 respuesta 1

0

Encontré la solución con esta cadena de texto.

lin = "update xcobrar set monto = " + CStr(monb).Replace(",", ".") + ", dolares = " + CStr(mond).Replace(",", ".") + " where nromov = " + nro

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.