• Welcome to Test Foro de elhacker.net SMF 2.1.
 

Problema al recorrer un Data Grid View!

Started by EnzO_D, 4 April 2017, 16:22 PM

0 Members and 1 Guest are viewing this topic.

EnzO_D

Buenos Dias! Les comento, estoy programando en C# con visual studio 2010 y base de datos SQL, tengo un DGV donde almaceno productos, luego necesito preguntar, si el producto existe en la base de dato? si existe lo actualizo pero, si no existe lo inserto, si agrego un producto anda bien, pero al insertar 2 productos juntos me toma el primer id, lo inserta y luego vuelve a tomar el primer id y lo modifica,no sigue con el otro! y la verdad es que no entiendo donde esta el error, desde ya muchas gracias!

aca dejo el codigo para que puedan entenderme un poco mas!

                        foreach (DataRow row in dtProducto.Rows)
                        {                           
                                rpta1 = NProducto_Venta.Consultar(Convert.ToInt32(this.dgvProducto.CurrentRow.Cells["idArticulo"].Value.ToString()));

                        if (rpta1 == "0")
                        {

                            rpta1 = NProducto_Venta.Insertar(this.dgvProducto.CurrentRow.Cells["Codigo"].Value.ToString(),
                                                             this.dgvProducto.CurrentRow.Cells["Nombre"].Value.ToString(),
                                                             this.dgvProducto.CurrentRow.Cells["Categoria"].Value.ToString(),
                                                             this.dgvProducto.CurrentRow.Cells["Presentacion"].Value.ToString(),
                                                             Convert.ToDecimal(this.dgvProducto.CurrentRow.Cells["Precio_Venta"].Value.ToString()),
                                                             Convert.ToInt32(this.dgvProducto.CurrentRow.Cells["Stock_Actual"].Value.ToString()),
                                                             Convert.ToDateTime(this.dgvProducto.CurrentRow.Cells["Fecha_Produccion"].Value.ToString()),
                                                             Convert.ToDateTime(this.dgvProducto.CurrentRow.Cells["Fecha_Vencimiento"].Value.ToString()),
                                                             Convert.ToInt32(this.dgvProducto.CurrentRow.Cells["idArticulo"].Value.ToString()));
                        }
                        else
                        {
                            if (rpta1 != "0")
                            {
                                rpta1 = NProducto_Venta.Editar(this.dgvProducto.CurrentRow.Cells["Codigo"].Value.ToString(),
                                                               this.dgvProducto.CurrentRow.Cells["Nombre"].Value.ToString(),
                                                               this.dgvProducto.CurrentRow.Cells["Categoria"].Value.ToString(),
                                                               this.dgvProducto.CurrentRow.Cells["Presentacion"].Value.ToString(),
                                                               Convert.ToDecimal(this.dgvProducto.CurrentRow.Cells["Precio_Venta"].Value.ToString()),
                                                               Convert.ToInt32(this.dgvProducto.CurrentRow.Cells["Stock_Actual"].Value.ToString()),
                                                               Convert.ToDateTime(this.dgvProducto.CurrentRow.Cells["Fecha_Produccion"].Value.ToString()),
                                                               Convert.ToDateTime(this.dgvProducto.CurrentRow.Cells["Fecha_Vencimiento"].Value.ToString()),
                                                               Convert.ToInt32(this.dgvProducto.CurrentRow.Cells["idArticulo"].Value.ToString()));
                            }