如何选择从数据库检索到的数据到datagridview的图像到winform图片框 [英] How to pick an image retreived from a database to a datagridview into a winform picturebox
本文介绍了如何选择从数据库检索到的数据到datagridview的图像到winform图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datagridview,它显示从数据库检索到的图像,我希望每当用户选择具有id列和picture列的行时,然后单击按钮,应从image列中选择图像并显示在图片框上
请提供有关如何执行此操作的任何帮助.
谢谢
I have a datagridview that display image retreived from a database, i want that when ever a user select the row e.g that has id column an picture column, and click on a button the image should be pick from the image column and diplayed on a picturebox
pls any help on how to do this.
Thanks
推荐答案
检查此
使用相同的数据源来绑定DataGrid
Hi ,
Check this
With the same Datasource you are using to bind your DataGrid
using (SqlConnection con = new SqlConnection(@"Data Source=pc\SQLEXPRESS;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=***"))
{
con.Open();
using (SqlCom
mand cmd = new SqlCommand("select * from ImageInsert", con))
{
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adpt.Fill(ds);
DataRow Row;
Row = ds.Tables[0].Rows[0];
byte[] MyImg = (byte[])Row[1];
MemoryStream ms = new MemoryStream(MyImg);
Image img = Image.FromStream(ms);
pictureBox1.Image = img;
}
}
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于如何选择从数据库检索到的数据到datagridview的图像到winform图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文