none
hello guys can u please help me how to save images in mysql? RRS feed

  • Question

  • Public Class Form1
    
        Dim f As New Capture
        Dim conn As New MySqlConnection("server='localhost'; uid='root'; pwd=''; database='cam';")
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Timer1.Start()
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Timer1.Stop()
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            Try
                PictureBox1.Image = f.QueryFrame.ToBitmap()
    
            Catch ex As Exception
                f = New Capture
    
            End Try
    
        End Sub
    
        Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
    
    
            Dim ms As New MemoryStream
            PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
            Dim dataBuff As Byte() = ms.GetBuffer()
            Dim p As New MySqlParameter("@img", MySqlDbType.LongBlob)
            Dim cmd As New MySqlCommand("insert into picture (image) values(@img)", conn)
            p.Value = dataBuff
            cmd.Parameters.Add(p)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
        End Sub
    
    End Class

    Wednesday, March 28, 2018 6:40 PM

Answers

All replies