0

このコードは現在機能しています。データベースに画像を保存したいのですが、どうすればよいか教えてください

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
    TextBox1.Text = OpenFileDialog1.FileName
    CaptionTextBox.Text = OpenFileDialog1.SafeFileName

    ' ImagePictureBox.Image = image.FromFile(TextBox1.Text)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    updateRecord("insert into uploadimages(caption,image) values('" + CaptionTextBox.Text + "', '@ImagePictureBox' )")
End Sub
4

1 に答える 1

0
     Imports MySql.Data.MySqlClient
    Imports System.Drawing.Imaging

    Dim cn As New MySqlConnection
        Dim con As New MySqlConnection
        Dim cmd As New MySqlCommand
        Dim dr As MySqlDataReader
        Dim da As MySqlDataAdapter
        Dim dt As New DataTable
        Dim abc As String

    private sub from1()
      cn.ConnectionString = "Server=localhost; user id=root; password=; database = school"
    cmd.Connection = cn
            cn.Open()
    end sub

 Private Sub images()
        Dim arrImage() As Byte
        Dim strImage As String
        Dim myMs As New IO.MemoryStream
        If Not IsNothing(Me.PictureBox5.Image) Then
            Me.PictureBox5.Image.Save(myMs, Me.PictureBox5.Image.RawFormat)
            arrImage = myMs.GetBuffer
            strImage = "1000"
        Else
            arrImage = Nothing
            strImage = "NULL"
        End If
        cmd.CommandText = "INSERT INTO admision(name, photo) VALUES('" & Me.TextBox1.Text & "'," & _
                               strImage & ")"

        If strImage = "1000" Then
            cmd.Parameters.Add(strImage, MySqlDbType.Blob).Value = arrImage

        End If

        MsgBox("Data save successfully!")
        clear()
        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub
于 2014-01-23T19:10:40.420 に答える