TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RobertoCarlos Melgar
1.6k
162
10.6k
modify a field of ten that I have in the table with entity f
May 27 2020 10:03 AM
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.
Reply
Answers (
2
)
How to check internet connection using C#
The modifier ‘private’ is not valid for this item