在C#窗口应用程序中将图像从sqlserver2005设置为picturebox1 [英] set a image from sqlserver2005 to the picturebox1 in c# window application

查看:112
本文介绍了在C#窗口应用程序中将图像从sqlserver2005设置为picturebox1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我在c#2008中有一个Windows应用程序.我想从sqlserver2005检索图像并将其设置为表单中的图片框.

我将代码写为::

Byte [] MyData = new Byte [4028];
MyData =(Byte [])dr ["PHOTO"];
MemoryStream ms =新的MemoryStream(MyData);
Frm.pictureBox1.Image = Image.FromStream(ms);
ms.Close();

Hello Friends,

I have a windows application in c# 2008.I want to retrieve a image from sqlserver2005 and set it to the picturebox in a form.

I write the code as::

Byte[] MyData = new Byte[4028];
MyData = (Byte[])dr["PHOTO"];
MemoryStream ms = new MemoryStream(MyData);
Frm.pictureBox1.Image = Image.FromStream(ms);
ms.Close();

推荐答案

我希望此帮助:-


i hope this help :-


MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0]["stdPhoto"]);
                    Image imgg = Image.FromStream(ms);
                    picStdPhoto.Image = imgg;


我看不到任何问题.如果您详细说明,那就太好了.告诉我们您遇到什么问题,或者遇到什么错误.
I can see no problem. It would be great if you elaborate more. Tell us what problem you have, or what error you get.
Byte[] byteBLOBData =  new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["BLOBData"]);
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
pictureBox1.Image= Image.FromStream(stmBLOBData);



参考: http://support.microsoft.com/kb/317701 [



Ref:http://support.microsoft.com/kb/317701[^]


我尝试了,它起作用了:
I tried it, it worked:
using (SqlConnection con = new SqlConnection(@"Data Source=GRIFFPC\SQLEXPRESS;Initial Catalog=myDatabase;Integrated Security=True"))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT image FROM myTable WHERE id=2", con))
        {
        SqlDataReader dr = com.ExecuteReader();
        dr.Read();
        byte[] MyData = new Byte[4028];
        MyData = (byte[]) dr["image"];
        MemoryStream ms = new MemoryStream(MyData);
        myPictureBox.Image = Image.FromStream(ms);
        ms.Close();
        }
    }

出了什么问题?


这篇关于在C#窗口应用程序中将图像从sqlserver2005设置为picturebox1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆