E
euchan09
Guest
Hi! I have an error in this code:
Pic.Image = Image.FromFile(Convert.ToString(ds.Tables("tbl_items").Rows(0).Field(Of String)("pic")))
says Unable to cast object of type 'System.Byte[]' to type 'System.String'. vb.net
and this is my full code:
Private Sub PopulateCheckBoxes()
Dim constr As String = "server=localhost; user id=root;password=root;database=eu"
Dim query As String = "select pic from tbl_items"
Using con As MySqlConnection = New MySqlConnection(constr)
Using sda As MySqlDataAdapter = New MySqlDataAdapter(query, con)
Dim ds As DataSet = New DataSet()
sda.Fill(ds, "tbl_items")
Dim datarow As DataRow
For Each datarow In ds.Tables(0).Rows
Dim mpnl As New Panel
mpnl.Width = 150
mpnl.Height = 190
Dim mPic As PictureBox = New PictureBox
mPic.Image = Image.FromFile(Convert.ToString(ds.Tables("tbl_items").Rows(0).Field(Of String)("pic")))
mPic.Width = 150
mPic.Height = 150
mPic.BorderStyle = BorderStyle.FixedSingle
mPic.SizeMode = PictureBoxSizeMode.Zoom
mpnl.Controls.Add(mPic)
FlowLayoutPanel1.Controls.Add(mpnl)
Next
End Using
End Using
End Sub
can anyone please help me to debug this? THANKS!
Continue reading...
Pic.Image = Image.FromFile(Convert.ToString(ds.Tables("tbl_items").Rows(0).Field(Of String)("pic")))
says Unable to cast object of type 'System.Byte[]' to type 'System.String'. vb.net
and this is my full code:
Private Sub PopulateCheckBoxes()
Dim constr As String = "server=localhost; user id=root;password=root;database=eu"
Dim query As String = "select pic from tbl_items"
Using con As MySqlConnection = New MySqlConnection(constr)
Using sda As MySqlDataAdapter = New MySqlDataAdapter(query, con)
Dim ds As DataSet = New DataSet()
sda.Fill(ds, "tbl_items")
Dim datarow As DataRow
For Each datarow In ds.Tables(0).Rows
Dim mpnl As New Panel
mpnl.Width = 150
mpnl.Height = 190
Dim mPic As PictureBox = New PictureBox
mPic.Image = Image.FromFile(Convert.ToString(ds.Tables("tbl_items").Rows(0).Field(Of String)("pic")))
mPic.Width = 150
mPic.Height = 150
mPic.BorderStyle = BorderStyle.FixedSingle
mPic.SizeMode = PictureBoxSizeMode.Zoom
mpnl.Controls.Add(mPic)
FlowLayoutPanel1.Controls.Add(mpnl)
Next
End Using
End Using
End Sub
can anyone please help me to debug this? THANKS!
Continue reading...