Para más detalle:
La tabla1 es la que comparo con el datagrid y es en la que se debe ACTUALIZAR
La tabla2 es en la que debo GUARDAR en el caso que la columna del datagrid sea diferente a la columna de la tabla1.
Mi problema es hacer la comparación de las columnas para crear el condicional
Estoy trabajando con vb.net y mi db es Mysql...el código que estoy manejando es el siguiente
Código vb:
Ver original
Private Sub btnTerminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTerminar.Click Dim num As String Dim val As Integer val = VALOR.Text num = preparar.Text menu_diario.grilla_menu.CurrentRow.Cells(3).Value = num menu_diario.grilla_menu.CurrentRow.Cells(4).Value = val Dim cont As String For i = 0 To grilla_productos.Rows.Count - 1 cont = grilla_productos.CurrentRow.Cells(3).Value Dim comando1 As New MySQLDriverCS.MySQLCommand comando1.Connection = cnn comando1.CommandType = CommandType.StoredProcedure comando1.CommandText = "select * FROM detalle_comp1" Dim cursor2 As New MySQLDriverCS.MySQLDataAdapter Dim dataset2 As New DataSet With cursor2 .SelectCommand = comando1 .Fill(dataset2, "t_detalle_comp1") End With Dim dr As System.Data.IDataReader dr = comando1.ExecuteReader() While dr.Read If cont = dr("cantidad") Then Dim id, medi, cant, prec As String For d = 0 To grilla_productos.Rows.Count - 1 id = grilla_productos.Rows(d).Cells(0).Value() medi = grilla_productos.Rows(d).Cells(2).Value() cant = grilla_productos.Rows(d).Cells(3).Value() prec = grilla_productos.Rows(d).Cells(4).Value() Dim modificar As New MySQLDriverCS.MySQLCommand modificar.Connection = cnn modificar.CommandType = CommandType.StoredProcedure modificar.CommandText = "UPDATE detalle_comp1 SET medida = '" & medi & "',cantidad='" & cant & "',precio = '" & prec & "' WHERE id_detalle='" & id & "'" modificar.ExecuteNonQuery() Next Me.Close() Else Dim id2, comp2, ingr2, medi2, cant2, prec2 As String For c = 0 To grilla_productos.Rows.Count - 1 id2 = grilla_productos.Rows(c).Cells(0).Value() comp2 = menu_diario.grilla_menu.CurrentRow.Cells(1).Value() ingr2 = grilla_productos.Rows(c).Cells(1).Value() medi2 = grilla_productos.Rows(c).Cells(2).Value() cant2 = grilla_productos.Rows(c).Cells(3).Value() prec2 = grilla_productos.Rows(c).Cells(4).Value() Dim guardar As New MySQLDriverCS.MySQLCommand guardar.Connection = cnn guardar.CommandType = CommandType.StoredProcedure guardar.CommandText = "INSERT INTO detalle_comp2 VALUES ('" & id2 & "','" & comp2 & "','" & ingr2 & "','" & medi2 & "','" & cant2 & "','" & prec2 & "')" guardar.ExecuteNonQuery() Next Me.Close() End If End While Next End Sub