简体   繁体   English

将图像字节类型从数据库显示到DataGridview C#中

[英]Display image byte type from database into DataGridview C#

Good Morning. 早上好。 I am Learning C# and I got a problem. 我正在学习C#,但遇到了问题。 I have my datagridView with some rows and columns. 我有一些行和列的datagridView。 So, I want to display to my datagridView image but, when do it, in the column "Imagem", show me "matriz byte[]", instead of my image. 因此,我想显示到我的datagridView图像,但是当执行此操作时,在“ Imagem”列中,显示“ matriz byte []”而不是图像。

The type of my "imagem" in my database is "Varbinary(MAX)". 我的数据库中“ imagem”的类型为“ Varbinary(MAX)”。 So, have something like 0Xffd8ff0001............ in my database. 因此,在我的数据库中有类似0Xffd8ff0001 ............的内容。

My code to load my data into datagridView is below. 下面是将数据加载到datagridView的代码。 the name of my DatagridView is "tabelAplicFerr": 我的DatagridView的名称是“ tabelAplicFerr”:

private void AplicadoresFerramentasControl_Load(object sender, EventArgs e)
    {

        try
        {
            SqlConnection con = new SqlConnection(Login.conectData);
            con.Open();
            DataSet dsFerramentas = new DataSet();
            SqlDataAdapter daFerramentas = new SqlDataAdapter("SELECT Ferramenta_ID,Imagem, Nome_Afinação, Vedante, Data_Criação, Observações, Utilizador FROM Ferramentas " +
                "JOIN FormasCravação ON FormasCravação.Cravação_ID = Ferramentas.Cravação_ID " +
                "JOIN TipoAfinação ON TipoAfinação.Afinação_ID = Ferramentas.Afinação_ID", con);

            dsFerramentas.Clear();
            daFerramentas.Fill(dsFerramentas, "Ferramentas");
            tabelAplicFerr.DataSource = dsFerramentas;
            tabelAplicFerr.DataMember = "Ferramentas";

            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

In my "SqlDataAdapter daFerramentas", I have in select "imagem". 在我的“ SqlDataAdapter daFerramentas”中,选择“ imagem”。 I get matrix byte[]", instead of my image. 我得到矩阵字节[]“,而不是我的图像。

How can I solve this problem? 我怎么解决这个问题?

I am using Visual Studio 2013, and SQL server 2008. 我正在使用Visual Studio 2013和SQL Server 2008。

Hope you can help me. 希望您能够帮助我。 Thank you. 谢谢。

在此处输入图片说明

I got the answer. 我得到了答案。

I went to my datagridView design, and I simply put a column with Type imageColumn. 我去了我的datagridView设计,我只用Type imageColumn放置了一个列。 follow the printscreen to see more details. 按照打印屏幕查看更多详细信息。

Click to add new column and after that I choose DatagrideViewImageColum. 单击以添加新列,然后选择DatagrideViewImageColum。 In my datagridView now show the image. 现在在我的datagridView中显示图像。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM