从sql server数据库中检索图像 [英] Retrieve Images from sql server database

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

问题描述

我正在将图像存储到数据库中。如何从数据库中检索所有图像。

i am storing images to the database. How to retrieve all the images from the database.

例如:从图像表中选择图像

Eg: select images from imagetable

问题:

数据逻辑:

           while (dr.Read())
          {
             ///Check for null
              if (!dr.IsDBNull(0))
             {
                try
                {
                    ///Converting the image into bitmap
                    byte[] photo = (byte[])dr[0];
                    ms = new MemoryStream(photo);
                    Bitmap bm = new Bitmap(ms);
                    bmp[i] = bm;

                    ms.Close();

                }
                catch (Exception ex)
                {

                }
            }

ASpx.CS页面:

ASpx.CS page:

Bitmap[] bm= photos.GetImage();
    for (int i = 0; i < bm.Length; i++)
    {
  MemoryStream ms = new MemoryStream();

        **bm[i].Save(ms, ImageFormat.Jpeg);**(Error : A generic error occurred in GDI+.)

htmlCode.Append("<li><img ImageUrl=\\\"");
htmlCode.Append(**ms.GetBuffer()**);
htmlCode.Append("\" alt=\"\" width=\"100\" height=\"100\"></li>");
}

图片未显示

Geetha

推荐答案

这是来自Sql Server的示例

this is an example from Sql Server

        connection.Open();
        SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@param", connection);
        SqlParameter myparam = command1.Parameters.Add("@param", SqlDbType.NVarChar, 30);
        myparam.Value = txtimgname.Text;
        byte[] img = (byte[])command1.ExecuteScalar();
        MemoryStream str = new MemoryStream();
        str.Write(img, 0, img.Length);
        Bitmap bit = new Bitmap(str);
        connection.Close();

看这里
http://www.akadia.com/services/dotnet_read_write_blob.html

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

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