Display image byte type from database into DataGridview C#

时间:2018-12-03 12:50:56

标签: c# datagridview

Good Morning. I am Learning C# and I got a problem. I have my datagridView with some rows and columns. 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.

The type of my "imagem" in my database is "Varbinary(MAX)". So, have something like 0Xffd8ff0001............ in my database.

My code to load my data into datagridView is below. the name of my DatagridView is "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". I get matrix byte[]", instead of my image.

How can I solve this problem?

I am using Visual Studio 2013, and SQL server 2008.

Hope you can help me. Thank you.

enter image description here

1 个答案:

答案 0 :(得分:0)

我得到了答案。

我去了我的datagridView设计,我只用type imageColumn放置了一个列。按照打印屏幕查看更多详细信息。

单击以添加新列,然后选择DatagrideViewImageColum。现在在我的datagridView中显示图像。

enter image description here