从数据库检索图像并在图片框中显示图像时出错 [英] Error retriving the image from database and display image in picturebox

查看:91
本文介绍了从数据库检索图像并在图片框中显示图像时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一个textbox1和一个picturebox,我需要从数据库中检索图像并将此图像显示在picturebox中.

我的代码如下....

Dear All ,

I have one textbox1 and one picturebox , i need to retrive the image from database and display this image in picturebox.

my code is given below....

private void textBox1_TextChanged(object sender, EventArgs e)
       {
             if (textBox1.TextLength == 4)
               {
                   SqlConnection ConnCMS = new SqlConnection();
                   string SqlConnectionString;
                   SqlConnectionString = "Server=10.1.1.28; Database=cms;uid=sa; pwd=samesame;";
                   ConnCMS.ConnectionString = SqlConnectionString;
                   SqlCommand cmdSelect = new SqlCommand("select FingerImage from EmployeeFinger where EmployeeNo=@ID", ConnCMS);
                   cmdSelect.Parameters.Add("@ID", SqlDbType.NVarChar).Value = textBox1.Text;
                   SqlDataAdapter sqlDA = new SqlDataAdapter(cmdSelect);
                   DataSet ds = new DataSet();
                   sqlDA.Fill(ds, "EmployeeFinger");
                   int c = ds.Tables["EmployeeFinger"].Rows.Count;
                   if (c > 0)
                   {
                       Byte[] byteBLOBData = new Byte[0];
                       byteBLOBData = (Byte[])(ds.Tables["EmployeeFinger"].Rows[0]["FingerImage"]);
                       MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
                       pictureBox1.Image = Image.FromStream(stmBLOBData);

                   }
                   ConnCMS.Close();
               }
           }



但它在最后一行pictureBox1.Image = Image.FromStream(stmBLOBData);
给了我错误参数无效"
请帮助我

Thanks



but its give me the Error "Parameter is not valid" at the last line pictureBox1.Image = Image.FromStream(stmBLOBData);

please help me

thanks

推荐答案

首先检查用于保存图像的代码-听起来好像不喜欢数据格式.
当然,转换代码看起来就像我使用的代码一样,因此,如果数据正确,它应该可以工作.
Check the code you used to save the image in the first place - it sounds like it dislikes the data format.
Certainly the convert code looks just like the code I use, so it should work if the data is correct.


使用处理程序来检索图像.
use a handler to retrieve an image.


这篇关于从数据库检索图像并在图片框中显示图像时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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