首页 > 解决方案 > VB.net DataGridView not display the Data from MySql Data base

问题描述

I am trying to display the data from MySql database using DataGridView DataSource and MySqlDataAdapter filling a DataTable . Then the data goes into the DataGridView. I do not know what is the problem, everything seems right and my code is correct, but nothing is being displayed on my DataGridView.

 Try
            Me.DataGridViewp.DataSource = Nothing

            ConnDB()
            sqL = "SELECT picture FROM product"
            cmd = New MySqlCommand(sqL, conn)
            Dim dtSample As New DataTable
            Dim daSample As New MySqlDataAdapter(cmd)
            daSample.Fill(dtSample)

            Me.DataGridViewp.DataSource = dtSample

            conn.Close()
            conn.Dispose()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
End Sub

标签: mysqlvb.netdatagridview

解决方案


如果我理解正确,您正试图在 DatGridView 中显示图像。如果图像在数据库中作为字节数组可用,您应该会看到它们。否则,它将不会显示在 DatGridView 中。

在将图像保存到数据库之前,我使用以下函数将图像转换为字节数组。以下是在保存之前将其转换为字节数组的示例代码。(我将代码作为图像附加,因为当我将其粘贴到此处时,它没有正确显示格式)。您必须为此代码添加参考 (System.IO) 才能在您的相关表单中工作。

这对我有用,希望对你有帮助。

在此处输入图像描述.


推荐阅读