我收到了错误"连接必须有效且开放"

时间:2017-05-15 15:11:58

标签: mysql vb.net

Imports MySql.Data.MySqlClient

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim mstream As New System.IO.MemoryStream()
        picture_me.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim arrImage() As Byte = mstream.GetBuffer()
        mstream.Close()

        Try


            cmd = New MySqlCommand("insert into piccs(Photo,id) values(@image_data,@image_id")
            cmd.Parameters.AddWithValue("@image_data", Nothing)
            cmd.Parameters.AddWithValue("@image_id", arrImage)


            cmd.ExecuteNonQuery()
            MsgBox("saved")
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        conn()

    End Sub

    Private Sub browser_image_Click(sender As Object, e As EventArgs) Handles browser_image.Click
        Me.find_image.FileName = Nothing
        If find_image.ShowDialog() = DialogResult.OK Then
            ' Dim query1 As String
            ' cmd = New MySqlCommand
            'cmd.Connection = connect

            'query1 = "Insert into picss(id, Photo) values('" & TextBox1.Text & "','" & find_image.SafeFileNames(x) & "',@IMAGE,'" & Batch & "')"

            If Not Me.find_image.FileName = Nothing Then
                Me.picture_me.ImageLocation = find_image.FileName
            End If
        End If



    End Sub
End Class

0 个答案:

没有答案