C# 使用C从SQL Server检索图像并在WPF网格中显示#

C# 使用C从SQL Server检索图像并在WPF网格中显示#,c#,sql,sql-server,wpf,C#,Sql,Sql Server,Wpf,我想从我的应用程序中的SQL Server表中检索图片,该应用程序是用C#和WPF编写的。现在我可以得到所有的数据,还有图片文件,但是我看不到图片 我有以下代码来获取数据: dataGrid由7行组成,我希望最后一行是图片。我怎么做 SqlConnection SqlConn = new SqlConnection(); SqlConn.ConnectionString = Conexion.Cn; SqlConn.Open(); string CommandText = "SELECT *

我想从我的应用程序中的SQL Server表中检索图片,该应用程序是用C#和WPF编写的。现在我可以得到所有的数据,还有图片文件,但是我看不到图片

我有以下代码来获取数据:

dataGrid由7行组成,我希望最后一行是图片。我怎么做

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;

你需要这样的东西 您必须确定图像的行、字段

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);

@JuanCarlosOropeza的可能副本这是针对WPF的,因此不能完全确定您的重复建议是否适用。它不起作用。我使用WPF和Neitet.Table或DataGridViewImageCell exists。通过在主代码中使用Linq To SQL,以及在WPF页面中使用字典将其绑定到转换器,我已经解决了我的问题。因此,图像显示良好。