我正在尝试将图像从mysql显示到PictureBox,并将其设置为在表单加载时显示。但是当我的表单加载时,图片不会出现,代码显示没有错误。这是代码:
Private Sub frmStudentskiPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Konekcija = New MySqlConnection
Konekcija.ConnectionString = "server=localhost; userid=root; password=masterzlaja123; database=proba"
Dim Command As MySqlCommand
Dim reader As MySqlDataReader
Dim img() As Byte
Try
Konekcija.Open()
Dim Query As String
Query = "Select Slika from proba.studenti where Korisnicko_ime = '" & Label2.Text & "' "
Command = New MySqlCommand(Query, Konekcija)
reader = Command.ExecuteReader
While reader.Read()
img = reader.Item("Slika")
Dim mstream As New MemoryStream(img)
PictureBox1.Image = Image.FromStream(mstream)
End While
Konekcija.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Konekcija.Dispose()
End Try
End Sub
结束班