查看“二进制数据”存储在Gridview中的SQL数据库中的图像 [英] View the "Binary data" of an Image stored in an SQL Database in a Gridview

查看:77
本文介绍了查看“二进制数据”存储在Gridview中的SQL数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第四个位置,我存储了一个Image,它被存储为二进制数据。



我想在Gridview中查看存储在SQL数据库中的二进制数据。



我该怎么做?



没有错误代码,图像列甚至没有显示。

In the fourth position I have stored an Image and it is stored as "Binary data".

I want to view that "Binary data" stored in an SQL Database in a Gridview.

How do I do that?

No error codes the image column does not even display.

string connStr2 = ConfigurationManager.ConnectionStrings["ImageMDFdb"].ConnectionString;
string cmdStr2 = "SELECT * FROM [ImageTable];";
byte[] btImage = null;
DataSet ds = new DataSet();
try
{
    using (SqlConnection conn2 = new SqlConnection(connStr2))
    {
        using (SqlCommand cmd2 = new SqlCommand(cmdStr2, conn2))
        {
            conn2.Open();
            using (SqlDataAdapter da = new SqlDataAdapter(cmd2))
            {
                da.Fill(ds);
                btImage = (byte[])ds.Tables[0].Rows[0][3];
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            conn2.Close();
            cmd2.Dispose();
            conn2.Dispose();
        }
    }
}
catch (Exception ex)
{
    Label2.Text = "Gridview: " + ex.ToString();
}

推荐答案

请尝试以下链接



http: //www.dotnetfox.com/articles/store-images-to-database-and-bind-to-gridview-in-Asp-Net-1114.aspx



如何绑定Varbinary数据使用ASP.Net进行Gridview


检查以下网址



http://aspsnippets.com/Articles /Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx



希望以上网址帮助
Check the below url

http://aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx

Hope the above url helps





更好的方法是将图像存储在一个文件夹中,然后将图像的路径保存在表格中,这样你就可以在gridview中显示图像



谢谢
Hi
Better way is store the images in a folder and then save path of the image in table , so u can display images in the gridview

Thanks


这篇关于查看“二进制数据”存储在Gridview中的SQL数据库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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