本文介绍了在C#中从SQL Server检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\meekun.poon\\My Documents\\Visual Studio 2008\\Projects\\TrackLocation\\TrackLocation\\barcodePrinter.mdf;Integrated Security=True;User Instance=True"))
                    {
                        conn.Open();
                        using (SqlCommand cmd = new SqlCommand("SELECT ImageName FROM Image WHERE ImageID='PL001'", conn))
                        {
                            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                            DataSet dataSet = new DataSet();
                            adpt.Fill(dataSet, "Image");
                            DataRow Row;
                            Row = dataSet.Tables["Image"].Rows[0];
                            byte[] MyImg = (byte[])Row[0];
                            MemoryStream ms = new MemoryStream(MyImg);
                            ms.Position = 0;

                            Image img = Image.FromStream(ms); //error 

                         pictureBox1.Image = img;

                        }
                        conn.Close();
                    }


如何解决这个问题呢??? imagename是图像数据类型!错误消息->参数无效.紧急!!!感谢


how to solve this problem??? imagename is image data type!! error message->parameter is not valid. URGENT!!! thanks

推荐答案


这篇关于在C#中从SQL Server检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 21:46