elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / Problema al recorrer un Data Grid View! en: 4 Abril 2017, 16:22 pm
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!

Código:
                        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()));
                            }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines