Visual Basic - select from where no me busca correctamente

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

select from where no me busca correctamente

Publicado por jorge (3 intervenciones) el 04/11/2021 04:39:34
buenas noches amigoa

tengo un pequeño problema con la instrucion select from where, ya que no me busca conforme un datagridview, si tengo un datagridview y lo lleno, quiero que vaya a una tabla de acces me busque el registro con ese nombre y me actualice el inventario

es para un inventario. pero el problema que me toma la fila 1 del datagrid y en la busqueda me da el registro de la fila 3 y pues los valores los pone donde no van

podrian ayudarme

este es mi codigo

Private Sub BGuardarProd_Click(sender As Object, e As EventArgs) Handles BGuardarProd.Click

Dim Fila2 As DataGridViewRow = New DataGridViewRow
Dim cant, Cantidad, Precio, Iva, existencia, NuevoStock As Decimal
Dim pregunta, Fecha1, cambiafecha As String
Dim Descrip, Descripcion, Descripcion1, Unidad, Factura, PrecioVenta As String
Dim ActualizarGR, PrecioInicial, Precio1, Precio2 As String
Dim Comparar As String
Dim AGR As New OleDbCommand("SELECT * FROM [Facturas Entradas] WHERE No_de_Factura LIKE'" & TxFactura.Text & "%'", conn)

Dim CmA As OleDbDataReader
Dim CmP As OleDbDataReader

Call Cargaconexion()
CmA = AGR.ExecuteReader
CmA.Read()
If CmA.Read Then
MsgBox("Factura Existente")
MsgBox(CmA("No_de_Factura"))
Return
Else
MsgBox("No Existe Factura")
Factura = UCase(TxFactura.Text)
Fecha1 = DateTimePicker2.Value
cambiafecha = Format(Fecha1, "Short Date")

Dim CmF = New OleDbCommand("INSERT INTO [Facturas Entradas](No_de_Factura, Fecha, Proveedor, Importe_Sin_Iva, Importe_Con_Iva, Total)" & Chr(13) &
"VALUES(Factura, cambiafecha, TxProveedor.Text, TxImpSProd.text, TxIvaSProd,TxTotalProd.text)", conn)

CmF.Parameters.AddWithValue("@No_de_Factura", Factura)
CmF.Parameters.AddWithValue("@Fecha", cambiafecha)
CmF.Parameters.AddWithValue("@Proveedor", TxProveedor.Text)
CmF.Parameters.AddWithValue("@Importe_Sin_Iva", TxImpSProd.Text)
CmF.Parameters.AddWithValue("@Importe_Con_Iva", TxIvaSProd.Text)
CmF.Parameters.AddWithValue("@Total", TxTotalProd.Text)
CmF.ExecuteNonQuery()
End If
MsgBox("Total de Filas " & DataGridProdEnt.RowCount)

For i = 0 To DataGridProdEnt.RowCount - 1
MsgBox("Final al inicio " & i)
cant = DataGridProdEnt.Rows(i).Cells(2).Value

If cant = 0 Then
Return
End If

Descripcion = DataGridProdEnt.Rows(i).Cells(1).Value
cant = DataGridProdEnt.Rows(i).Cells(2).Value
Precio = DataGridProdEnt.Rows(i).Cells(4).Value
Dim AgP As New OleDbCommand("SELECT * FROM [Base de Datos Productos] WHERE Descripcion like'" & DataGridProdEnt.Rows(i).Cells(1).Value & "'And Municipio like'" & ComboCiudadProd.Text & "'", conn)

MsgBox("Cantidad en datagrid " & cant)
MsgBox("Datagrid descr " & DataGridProdEnt.Rows(i).Cells(1).Value)
MsgBox(dr("Descripcion"))
MsgBox(dr("Municipio"))
If DBNull.Value.Equals(dr("Stock")) Then
MsgBox("es null")
Else
existencia = dr("Stock")
End If

MsgBox("Stock en BD " & dr("Stock"))

PrecioInicial = dr("Precio_Costo_Actual") 'Pasara al Precio historico 1
Precio1 = dr("Precio_Historico_1") 'Pasara al Precio historico 2
NuevoStock = existencia + cant
MsgBox("Datos a guardar " & existencia & NuevoStock)

ActualizarGR = "UPDATE [Base de Datos Productos] SET Stock= '" & NuevoStock &
"', Precio_Costo_Actual='" & Precio &
"', Precio_Historico_1='" & PrecioInicial &
"', Precio_Historico_2='" & Precio1 &
"' WHERE Descripcion like'" & DataGridProdEnt.Rows(i).Cells(1).Value & "' And Municipio like'" & ComboCiudadProd.Text & "'"
MsgBox("Datagrid descr 2 " & DataGridProdEnt.Rows(i).Cells(1).Value)
MsgBox(dr("Descripcion"))

Comando = New OleDbCommand(ActualizarGR, conn)
Comando.Parameters.AddWithValue("@Stock", NuevoStock)
Comando.Parameters.AddWithValue("@Precio_Costo_Actual", Precio)
Comando.Parameters.AddWithValue("@Precio_Historico_1", PrecioInicial)
Comando.Parameters.AddWithValue("@Precio_Historico_2", Precio1)
Comando.ExecuteNonQuery()

Next

MsgBox("No de Factura guardada con exito")
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder