How to add image from database to PictureBox?

后端 未结 5 762
半阙折子戏
半阙折子戏 2020-12-10 21:05

I am using this to get image bytes from the database

cmd.CommandText = \"select imagedate from projectimages where imagename = \'\" + _
    ListBox1.Text + \         


        
5条回答
  •  旧巷少年郎
    2020-12-10 21:53

    here's my code to show blob file to picturebox in vb.net. hope it helps

    Dim connstring As String = "Database=pmk;data source=localhost;user id=root;password="
    Dim Sql As String = "select * from mastermahasiswa where Nim='" & TextBox1.Text & "'"
    Dim conn As New MySqlConnection(connstring)
    Dim cmd As New MySqlCommand(Sql, conn)
    Dim dr As MySqlDataReader = Nothing
    conn.Open()
    dr = cmd.ExecuteReader()
    dr.Read()
    Dim imagebytes As Byte() = CType(dr("Foto"), Byte())
    Using ms As New IO.MemoryStream(imagebytes)
        PictureBox1.Image = Image.FromStream(ms)
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Using
    conn.Close()
    

提交回复
热议问题