2

I want to retrieve pictures from a SQL Server table in my application written in C# with WPF. Right now I can get all the data, and also the picture file, but I can't see the picture.

I have this code to fetch the data:

The dataGrid is formed by 7 rows, and I want the last row to be the picture. How can I do it?

SqlConnection SqlConn = new SqlConnection();

SqlConn.ConnectionString = Conexion.Cn;
SqlConn.Open();

string CommandText = "SELECT * FROM datos_personales WHERE [nombre]= @texto_buscar";

SqlCommand SqlCmd = new SqlCommand(CommandText, SqlConn);

SqlCmd.Parameters.AddWithValue("@texto_buscar", this.TextFirstName.Text);

SqlDataAdapter adapter = new SqlDataAdapter(SqlCmd);
DataTable dt = new DataTable("datos_personales");
adapter.Fill(dt);

dataListado.ItemsSource = dt.DefaultView;

SqlConn.Close();
this.TextFirstName.Text = string.Empty;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • possible duplicate of [How to show a image in database in the image control of Asp.net?](http://stackoverflow.com/questions/2482104/how-to-show-a-image-in-database-in-the-image-control-of-asp-net) – Juan Carlos Oropeza Sep 07 '15 at 15:51
  • @JuanCarlosOropeza this is for WPF, so not entirely sure your duplicate suggestion applies. – Clint Sep 07 '15 at 16:39

1 Answers1

0

You need something like this You have to determinate what row, field your image is.

adapter.Fill(dt);

byte [] data=new byte[0];
data =(byte[])(ds.Tables[0].Rows[0][0]);
MemoryStream ms = new MemoryStream(data);
DataGridViewImageCell img = new DataGridViewImageCell();
img.Image = Image.FromStream(ms);
img.Name = "Image";
yourdatagridview.Columns.add(img);
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • It does not work. I use WPF and neithet .Table or DataGridViewImageCell exists. – Botez Adrian Sep 08 '15 at 08:23
  • I have solved my problem by using Linq To SQL in the main code, and also using a Dictionary in the WPF page binding it to a converter. So the images are showed well. – Botez Adrian Sep 15 '15 at 06:34