简体   繁体   English

VB.net DataGridView 不显示来自 MySql 数据库的数据

[英]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 .我正在尝试使用DataGridView DataSourceMySqlDataAdapter填充DataTable来显示MySql database中的数据。 Then the data goes into the DataGridView .然后数据进入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 .我不知道问题出在哪里,一切似乎都正确,我的代码也正确,但我的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

If I understood you correctly, you are trying to show an image in a DatGridView.如果我理解正确,您正试图在 DatGridView 中显示图像。 You should see your images if they are available in the database as byte array.如果图像在数据库中作为字节数组可用,您应该会看到它们。 otherwise, it will not be shown in the DatGridView.否则,它将不会显示在 DatGridView 中。

I use the following function to convert images to byte array before saving it to the database.在将图像保存到数据库之前,我使用以下 function 将图像转换为字节数组。 Following is a sample code to convert it to byte array before saving.以下是在保存之前将其转换为字节数组的示例代码。 (I am attaching the code as an image since it does not show correctly formatted when I paste it here). (我将代码作为图像附加,因为当我将其粘贴到此处时,它没有正确显示格式)。 You have to add a reference (System.IO) for this code to work in your relevant form.您必须为此代码添加参考 (System.IO) 才能在您的相关表单中工作。

This works for me and hope this helps you.这对我有用,希望这对你有帮助。

在此处输入图像描述 . .

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

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