Ir al contenido


Foto

problemas con el datagrid y la base de datos


  • Por favor identifícate para responder
1 respuesta en este tema

#1 alcapone

alcapone

    Newbie

  • Miembros
  • Pip
  • 3 mensajes

Escrito 18 mayo 2013 - 03:58

Dim numfactura As Integer
    Dim i As Integer = 0
    Dim total As Double
    Dim conec As New conectorbd("root", "root123")
    Dim query As String
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncerrar.Click
        Me.Close()
        menumorlis.Visible = True
    End Sub

    Private Sub txtidcliente_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtidcliente.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub txtidcliente_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtidcliente.TextChanged
        query = "select * from clientes where idclientes = '" & txtidcliente.Text & "' "
        consul = conec.consulta(query)
        While consul.Read
            txtidcliente.Text = consul.GetValue(0).ToString
            txtnombrecliente.Text = consul.GetValue(1).ToString
            txtapellidocliente.Text = consul.GetValue(2).ToString
            txttelefonocliente.Text = consul.GetValue(3).ToString
            txtcelularcliente.Text = consul.GetValue(4).ToString
            txtcedulacliente.Text = consul.GetValue(5).ToString
            txtdireccioncliente.Text = consul.GetValue(6).ToString
        End While
    End Sub

    Private Sub GroupBox5_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox5.Enter

    End Sub

    Private Sub txtvalor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtvalor.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub txtextra_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtextra.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub txtprendas_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtprendas.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub txtdescuento_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtdescuento.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub


    Private Sub recibo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        query = "select max(idrecibo) from recibo"
        consul = conec.consulta(query)
        While consul.Read
            numfactura = consul.GetValue(0).ToString
        End While
        numfactura = numfactura + 1
        txtnrecibo.Text = numfactura
    End Sub

    Private Sub txttotal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttotal.KeyPress
        If Char.IsDigit(e.KeyChar) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
    End Sub

    Private Sub btningresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btningresar.Click

        With DataGridView1
            .Rows.Add()
            .Item(0, i).Value = txtnrecibo.Text
            .Item(1, i).Value = txtidcliente.Text
            .Item(2, i).Value = txtnombrecliente.Text
            .Item(3, i).Value = txtapellidocliente.Text
            .Item(4, i).Value = txttelefonocliente.Text
            .Item(5, i).Value = txtcelularcliente.Text
            .Item(6, i).Value = txtcedulacliente.Text
            .Item(7, i).Value = txtdireccioncliente.Text
            .Item(8, i).Value = cbtipo.Text
            .Item(9, i).Value = cbcolor.Text
            .Item(10, i).Value = txtmarca.Text
            .Item(11, i).Value = cbmaterial.Text
            .Item(12, i).Value = txtvalor.Text
            .Item(13, i).Value = txtprendas.Text
            .Item(14, i).Value = txtdescuento.Text
            .Item(15, i).Value = txttotal.Text
            .Item(16, i).Value = cbestado.Text
            .Item(17, i).Value = DateTimePicker1.Text
            .Item(18, i).Value = DateTimePicker2.Text
            .Item(19, i).Value = txtempleado.Text
            .Item(20, i).Value = horaentrega.Text
            .Item(21, i).Value = fechaentrega.Text
        End With
        i += 1

        '******************************+
        txtextra.Text = ""
        cbtipo.Text = ""
        cbcolor.Text = ""
        txtmarca.Text = ""
        cbmaterial.Text = ""
        txtvalor.Text = ""
        txtprendas.Text = ""
        txtdescuento.Text = ""
        txttotal.Text = ""
        cbestado.Text = ""
        DateTimePicker1.Text = ""
        DateTimePicker2.Text = ""
        txtempleado.Text = ""
        horaentrega.Text = ""
        fechaentrega.Text = ""
    End Sub

    Private Sub btnterminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnterminar.Click

   
en esta parte es que necesito ayuda ''''''''' necesito el dodigo para guardar los datos del datagrid en la base y tambien es que por decirlo de alguna manera la factura tiene varios articulos es decir que en la misma factura guardo 1 o mas articulos

    End Sub


porfa varias obciones por si no funcionan



gracias
  • 0

#2 novato

novato

    Member

  • Miembros
  • PipPip
  • 35 mensajes

Escrito 09 julio 2013 - 07:38

HOLA AMIGO COMO ESTA AHORITA NO TENGO TIEMPO PARA AYUDARTE COMPLETAMENTE AQUI TE DEJO EL CODIGO
PARA GUARDAR DEL GRID  A LA BD
ESTO ES EN VBNET YO USO LAS ETIQUETAS PHP PORQ SE MIRA MAS ORDENADO EL CODIGO


  For i As Integer = 0 To DataGridView2.Rows.Count - 1
                'creamos la sentencia el row siempre tendra el valor de i para ir pasando de row en row
                'el campo .cells(0) indica la columna que esta ese dato, tambien puede hacerlo con el nombre de la celda .cells("Nombre")
                'SqlString = "INSERT INTO factura (descripcion,marca,cantidad,punitario,fecha,subtotal,iva,monto) VALUES (" + DataGridView2.Rows(i).Cells(0).Value.ToString() + "," + DataGridView2.Rows(i).Cells(1).Value.ToString() + "," + DataGridView2.Rows(i).Cells(2).Value.ToString() + "," + DataGridView2.Rows(i).Cells(3).Value.ToString() + "," + DataGridView2.Rows(i).Cells(4).Value.ToString() + "," + Val(txtmonto.Text) + "," + Val(lbiva.Text) + "," + Val(txttotal.Text) + ")"
                'SqlString = "INSERT INTO factura (descripcion,marca,cantidad,punitario,fecha,subtotal,iva,monto) VALUES (" + DataGridView2.Rows(i).Cells(0).Value.ToString() + "," + DataGridView2.Rows(i).Cells(1).Value.ToString() + "," + DataGridView2.Rows(i).Cells(2).Value.ToString() + "," + DataGridView2.Rows(i).Cells(3).Value.ToString() + "," + DataGridView2.Rows(i).Cells(4).Value.ToString() + "," + a + "," + b + "," + c + ")"
                Dim savetotales As New SqlCommand("INSERT INTO factura (descripcion,marca,cantidad,punitario,fecha,subtotal,iva,monto) VALUES (@descripcion,@marca,@cantidad,@punitario,@fecha,@subtotal,@iva,@monto)", cnx)
                With savetotales
                    .Parameters.Add(New SqlParameter("descripcion", _
                        SqlDbType.NVarChar, 50)).Value = Me.DataGridView2.Rows(i).Cells(0).Value.ToString()
                    .Parameters.Add(New SqlParameter("marca", _
                        SqlDbType.NVarChar, 50)).Value = Me.DataGridView2.Rows(i).Cells(1).Value.ToString()
                    .Parameters.Add(New SqlParameter("cantidad", _
                        SqlDbType.NVarChar, 50)).Value = Me.DataGridView2.Rows(i).Cells(2).Value.ToString()
                    .Parameters.Add(New SqlParameter("punitario", _
                        SqlDbType.NVarChar, 50)).Value = Me.DataGridView2.Rows(i).Cells(3).Value.ToString()
                    .Parameters.Add(New SqlParameter("fecha", _
                        SqlDbType.DateTime)).Value = Me.DataGridView2.Rows(i).Cells(4).Value.ToString()
                    .Parameters.Add(New SqlParameter("@subtotal", _
                        SqlDbType.Money, 8)).Value = Me.txtmonto.Text
                    .Parameters.Add(New SqlParameter("@iva", _
                        SqlDbType.Money, 8)).Value = Me.lbiva.Text
                    .Parameters.Add(New SqlParameter("@monto", _
                        SqlDbType.Money, 8)).Value = Me.txttotal.Text
                End With
                savetotales.ExecuteNonQuery()

  • 0




IP.Board spam blocked by CleanTalk.