Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
2
Answers
modify a field of ten that I have in the table with entity f
RobertoCarlos Melgar
4y
776
1
Reply
Very good day. I have a table to which I only want to modify the image in a field
I just need to change the image field, for this I do the following
public
partial
class
tblProducto {
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage"
,
"CA2214:DoNotCallOverridableMethodsInConstructors"
)]
public
tblProducto() {
this
.tblDetalleVentas =
new
HashSet < tblDetalleVenta > ();
this
.tblKardexes =
new
HashSet < tblKardex > ();
this
.tblDetalleIngresoProductos =
new
HashSet < tblDetalleIngresoProducto > ();
}
public
int
Id {
get
;
set
;
}
public
int
Categoria_Id {
get
;
set
;
}
public
int
UnidadMedida_Id {
get
;
set
;
}
public
string
Codigo {
get
;
set
;
}
public
string
ProductoDescripcion {
get
;
set
;
}
public
Nullable <
decimal
> PrecioVenta {
get
;
set
;
}
public
Nullable <
decimal
> Stock {
get
;
set
;
}
public
System.DateTime FechaCreado {
get
;
set
;
}
public
string
NombreImagen {
get
;
set
;
}
public
byte
[] Imagen {
get
;
set
;
}
public
int
Estado_Id {
get
;
set
;
}
public
int
Usuario_Id {
get
;
set
;
}
public
virtual
tblCategoria tblCategoria {
get
;
set
;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage"
,
"CA2227:CollectionPropertiesShouldBeReadOnly"
)]
public
virtual
ICollection < tblDetalleVenta > tblDetalleVentas {
get
;
set
;
}
public
virtual
tblEstado tblEstado {
get
;
set
;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage"
,
"CA2227:CollectionPropertiesShouldBeReadOnly"
)]
public
virtual
ICollection < tblKardex > tblKardexes {
get
;
set
;
}
public
virtual
tblUnidade tblUnidade {
get
;
set
;
}
public
virtual
tblUsuario tblUsuario {
get
;
set
;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Usage"
,
"CA2227:CollectionPropertiesShouldBeReadOnly"
)]
public
virtual
ICollection < tblDetalleIngresoProducto > tblDetalleIngresoProductos {
get
;
set
;
}
}
I have the following method
public
static
void
ModificarImagen(tblProducto objProducto)
{
using
(GourmetEntities db =
new
GourmetEntities())
{
db.tblProductos.Attach(objProducto);
db.Entry(objProducto).Property(x => x.Imagen).IsModified =
true
;
db.SaveChanges();
}
}
in the button event I have the following code
private
void
BtnModificar_Click(
object
sender, EventArgs e) {
//try
//{
byte
[] Imagen =
null
;
Stream myStream = openFileDialog1.OpenFile();
using
(MemoryStream ms =
new
MemoryStream()) {
myStream.CopyTo(ms);
Imagen = ms.ToArray();
}
foreach
(var item
in
ListaProductos) {
ObjProducto.Imagen = Imagen;
}
tblProducto.ModificarImagen(ObjProducto);
//ObjProducto.Id = IdProducto;
//ObjProducto. = "NO CAMBIAR";
//ObjProducto.Estado_Id = 0;
//ObjProducto.Imagen = Imagen;
// MessageBox.Show("Datos modificados correctamente", "INFORMACIÓN DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
//}
//catch (Exception ex)
//{
// MessageBox.Show("Ocurrio un problema, los datos no se modificaron", "INFORMACIÓN DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
//}
}
but I get the following error,
it tells me that all the fields are mandatory. How can I solve this problem if you please, since there are 1000 fields, I must write the thousand fields. please help with this problem for me
RM.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to check internet connection using C#
The modifier ‘private’ is not valid for this item