使用MysqlDataAdapter时出错

时间:2016-06-02 23:23:57

标签: mysql vb.net

我正在关注互联网上的教程(link)来创建图片库。我把它全部搞定了,但我改变了:

Private Sub CreateGallery()
        i = 0
        RemoveControls()
        If Directorypath IsNot Nothing Then
            Dim di As New IO.DirectoryInfo(Directorypath)
            Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg").Concat(di.GetFiles("*.bmp")).Concat(di.GetFiles("*.png")).Concat(di.GetFiles("*.gif")).ToArray
            Dim dra As IO.FileInfo
            For Each dra In diar1
                DrawPictureBox(dra.FullName, dra.Name)
            Next
        End If
    End Sub

为:

Private Sub CreateGallery()
        Dim table = New DataTable
        Using Connection = New MySqlConnection("Server=localhost;User Id=root;Password=barra;Database=pap")
            Using da = New MySqlDataAdapter("SELECT * FROM filme", Connection)
                da.Fill(table)
            End Using
        End Using
        i = 0
        RemoveControls()
        For Each row As DataRow In table.Rows
            Try
                Dim bytes() As Byte
                bytes = (row("imagem"))
                Dim memStream As New MemoryStream(bytes)
                DrawPictureBox(memStream, row("titulo"))
            Catch ex As Exception
            End Try
        Next
    End Sub

它工作正常,我想要的方式,当我尝试在另一个项目上执行它时,它给我一个错误' MySqlDataAdapter':

Using da = New MySqlDataAdapter("SELECT * FROM filme", Connection)
错误说:过载解决方案失败了,因为没有可访问的'新的'可以用这些参数调用

我几乎尝试了所有能让它发挥作用的东西。

2 个答案:

答案 0 :(得分:0)

将您的函数转换为类并调用:

dim new_creator as yourclass

...

答案 1 :(得分:0)

试试这个

   Private Sub CreateGallery()
    Dim table As New DataTable
    Dim Conn As New SqlConnection
    Conn = New SqlConnection("Initial Catalog=<DataBase>;User ID=sa;password=<password>;Data Source=<ServerName>"")
    Dim com As String = ""
    com = "SELECT * FROM Table "
    Dim getComm As New SqlDataAdapter(com, Conn)
    getComm.Fill(table)
    i = 0
    RemoveControls()
    For Each row As DataRow In table.Rows
        Dim bytes() As Byte
        bytes = (row("Imagee"))
        Dim memStream As New MemoryStream(bytes)
        DrawPictureBox(memStream, row("Bro_Path"))
    End Sub

并将ByVal _filename更改为MemoryStream,

    Private Sub DrawPictureBox(ByVal _filename As MemoryStream, ByVal _displayname As String)