0
我試圖查看從datagridview到文本框和圖片框的圖像的所有信息。但是如果我的Isbn有破折號( - )或字母,那就錯了。從字符串「」轉換爲「長」類型的轉換無效。 VB.net
我的代碼是這些
Private Sub Load_Image(ByVal iIMageID As Long)
Dim sConnString As String
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim reader As MySqlDataReader
Try
Call ConnectDatabase()
Dim query As String
query = "select ISBN, Subject, BookName, Publisher, Author, PublishingYear, Status, image from Books where ISBN= " & iIMageID
Command = New MySqlCommand(query, conn)
reader = Command.ExecuteReader
If reader.HasRows Then
While reader.Read
Label2.Text = reader("ISBN")
Label3.Text = reader("Subject")
Label1.Text = reader("BookName")
Label4.Text = reader("Publisher")
Label5.Text = reader("Author")
Label6.Text = reader("PublishingYear")
Label7.Text = reader("Status")
arrImage = reader("image")
For Each ar As Byte In arrImage
myMS.WriteByte(ar)
Next
'
Me.PictureBox1.Image = System.Drawing.Image.FromStream(myMS)
End While
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close()
End Try
End Sub
然後在CellcontentClick事件
Load_Image(Me.MetroGrid1.Item(0, Me.MetroGrid1.CurrentRow.Index).Value.ToString)
謝謝先生..它的工作原理:) –
不客氣。如果這有效,請接受我的答覆爲「已回答」。 – JerryM