Public Sub CargarProducto()
Try
oDataAdapterP = New SqlDataAdapter("SELECT Productos.* FROM Productos " & _
" WHERE Id_Categoria = " & iCategoria, CnSql)
'creo commandbuilder
Dim oComBuilder As New SqlCommandBuilder(oDataAdapterP)
'creo el dataset
oDataSetP = New DataSet
'abro la conexion
CnSql.Open()
'cargo el dataset
oDataAdapterP.Fill(oDataSetP, "Productos")
CnSql.Close()
Dim oDataRowP As DataRow
PictureBox2.Image = Nothing 'limpio el picturebox
If oDataSetP.Tables("Productos").Rows.Count > 0 Then
oDataRowP = oDataSetP.Tables("Productos").Rows(iPosicionFilaActualP)
txtProducto.Text = CStr(oDataRowP("NombreProducto"))
txtPrecio.Text = CStr(oDataRowP("Precio"))
iProducto = CInt(oDataRowP("id_Producto")) 'variable para modificar mas tarde
'pregunto si exite una foto
If Not oDataRowP("Foto") Is DBNull.Value Then
MostrarImagenPict(Me.PictureBox2, CInt(oDataRowP("Foto"))) 'carga la foto en li picture
End If
Else
txtProducto.Text = ""
txtPrecio.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "SISTEMA MACHADO")
End Try
End Sub
Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
'este procedimiento el k acepta los cambio...
Try
Dim oDataRow As DataRow
oDataRow = Me.oDataSetC.Tables("Categorias").Rows(Me.iPosicionFilaActualC)
oDataRow("NombreCategoria") = Trim(txtCategoria.Text)
Me.oDataAdapterC.Update(Me.oDataSetC, "Categorias")
If txtProducto.Enabled = True Then 'pregutno si hay producto en la categoria
Dim oDataRowP As DataRow
oDataRowP = oDataSetP.Tables("Productos").Rows(iPosicionFilaActualP)
oDataRowP("NombreProducto") = Trim(txtProducto.Text
If Me.PictureBox2.Image IsNot Nothing Then 'pregunto si tengo una imagen
oDataRowP("Foto") = iProducto
End If
oDataAdapterP.Update(oDataSetP, "Productos")
'aka trate d liberar los recursos pero no pasa nada
oDataSetP = Nothing
oDataSetC = Nothing
oDataAdapterC = Nothing
oDataAdapterP = Nothing
oDataRowP.Delete()
If Me.PictureBox2.Image IsNot Nothing Then
File.
Delete(Path.
GetFullPath("Fotos") & "" & iProducto
)'aka me da el error Else
File.
Delete(Path.
GetFullPath("Fotos") & "" & iProducto
)'aka tmb! End If
End If
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxstyle.Critical, "SISTEMA MACHADO")
End Try
End Sub