¿Como mostrar imagen almacenada en una base de datos en un picturebox?

Tengo un pequeño problema estoy intentando mostrar una imagen en un picturebox la cual esta almacenada en una base de datos, pero la quiero llamar utilizando el evento del datagridview doubleclick y no he podido, sera que tu puedes ayudarme o recomendarme como llamar la imagen

1 Respuesta

Respuesta
1

me supongo que es en aspx cierto, lo que debes hacer es obtener el byte[] primero y luego ese byte[] tranformarlo a un source deln picturebox y asignarlo al picturebox

Saludos si no es aspx me avisas en que es y si necesitas algún código por ahí para buscártelo

no es un aspx ,es un proyecto winforms lo que necesito es en el momento que yo le de click en el datagridview (utilizando evento doubleclick) me traiga la imagen que y me la muestre en el picturebox

espero me hayas entendido

Que tal te pongo el código fuente saludos

---FORMULARIO

namespace
Imagen
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#región
Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgvDatos = new System.Windows.Forms.DataGridView();
this.pbImagen = new System.Windows.Forms.PictureBox();
((System.ComponentModel.
ISupportInitialize)(this.dgvDatos)).BeginInit();
((System.ComponentModel.
ISupportInitialize)(this.pbImagen)).BeginInit();
this.SuspendLayout();
//
// dgvDatos
//
this.dgvDatos.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDatos.Location = new System.Drawing.Point(13, 13);
this.dgvDatos.MultiSelect = false;
this.dgvDatos.Name = "dgvDatos";
this.dgvDatos.ReadOnly = true;
this.dgvDatos.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvDatos.Size = new System.Drawing.Size(563, 524);
this.dgvDatos.TabIndex = 0;
this.dgvDatos.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvDatos_CellMouseDoubleClick);
//
// pbImagen
//
this.pbImagen.Location = new System.Drawing.Point(582, 12);
this.pbImagen.Name = "pbImagen";
this.pbImagen.Size = new System.Drawing.Size(266, 525);
this.pbImagen.TabIndex = 1;
this.pbImagen.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(860, 549);
this.Controls.Add(this.pbImagen);
this.Controls.Add(this.dgvDatos);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.
ISupportInitialize)(this.dgvDatos)).EndInit();
((System.ComponentModel.
ISupportInitialize)(this.pbImagen)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dgvDatos;
private System.Windows.Forms.PictureBox pbImagen;
}
}

---CÓDIGO FUENTE

using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.IO;
namespace
Imagen
{
public partial class Form1 : Form
{
DataClassesDataContext data = new DataClassesDataContext();
public Form1()
{
InitializeComponent();
dgvDatos.DataSource = data.VMS_ARTICULOs;
}
private void dgvDatos_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
decimal codigoArticulo = decimal.Parse(dgvDatos.SelectedRows[0].Cells[1].Value.ToString());
VMS_ARTICULO obj = data.VMS_ARTICULOs.Where(p => p.codigoEmpresa == 1 && p.codigoArticulo == codigoArticulo).Single();
CargarInformacion(obj);
}
catch (Exception ex)
{
MessageBox.Show("Error - " + ex.Message);
}
}
private void CargarInformacion(VMS_ARTICULO obj)
{
try
{
if (obj != null)
{
MemoryStream ms = new MemoryStream(obj.imagen.ToArray());
pbImagen.Image =
Image.FromStream(ms);
}
}
catch (Exception ex)
{
MessageBox.Show("Error - " + ex.Message);
}
}
}
}

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas