Está en la página 1de 2

Dim Conn As New OleDbConnection("Aqu tu cadena de conexion")

Try
Conn.Open()
For X As Integer = 0 To DataGridView1.Rows.Count - 1
Using cmdInsert As New OleDbCommand
With cmdInsert
.CommandText = " INSERT INTO DetallesFactura (IdFactura,
Cantidad, Codigo, Detalle, Descuento, Precio, Importe) VALUES (@IdFactura,@Cant
idad,@Codigo,@Detalle,@Descuento,@Precio,@Importes)"
.CommandType = CommandType.Text
.Connection = Conn
.Parameters.Add("@IdFactura", OleDbType.Integer).Value =
Convert.ToInt32(DataGridView1.Rows(X).Cells("IdFactura").Value)
.Parameters.Add("@Cantidad", OleDbType.Integer).Value =
Convert.ToInt32(DataGridView1.Rows(X).Cells("Cantidad").Value)
.Parameters.Add("@Codigo", OleDbType.VarChar).Value = Da
taGridView1.Rows(X).Cells("Codigo").Value.ToString
.Parameters.Add("@Detalle", OleDbType.VarChar).Value = D
ataGridView1.Rows(X).Cells("Detalle").Value.ToString
.Parameters.Add("@Descuento", OleDbType.Double).Value =
Convert.ToDouble(DataGridView1.Rows(X).Cells("Descuento").Value)
.Parameters.Add("@Precio", OleDbType.Double).Value = Con
vert.ToDouble(DataGridView1.Rows(X).Cells("Precio").Value)
.Parameters.Add("@Importes", OleDbType.Double).Value = C
onvert.ToDouble(DataGridView1.Rows(X).Cells("Importes").Value)
End With
Dim Correcto As Integer = cmdInsert.ExecuteNonQuery
If Correcto = 0 Then
MessageBox.Show("Error no se pudo agregar la fila", "Adv
ertencia", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Using
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK, Mes
sageBoxIcon.Error)

Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
Conn.Dispose()
End If
End Try
Return True
End Function

También podría gustarte