我有一個數據網格視圖中,在更新按鈕i寫這樣的代碼:無法轉換類型的對象「System.Byte []」中的窗口的應用程序類型「爲System.Drawing.Image」
Dim cid As Integer
Dim dtid As Integer
Dim cmpname As String
Dim dtname As String
Dim dtPhone As String
Dim dtEmail As String
Dim dtimage As Image
For i As Integer = 0 To gv.RowCount - 2
' Dim rv = DirectCast(bSource.Current, DataRowView)
Dim rv = DirectCast(gv.Rows(i).DataBoundItem, DataRowView)
cid = rv.Row.Field(Of Integer)("Cid")
dtid = rv.Row.Field(Of Integer)("dtId")
cmpname = rv.Row.Field(Of String)("CompanyName")
dtname = rv.Row.Field(Of String)("Department")
dtPhone = rv.Row.Field(Of String)("Phone")
dtEmail = rv.Row.Field(Of String)("Email")
dtimage = rv.Row.Field(Of Image)("empimage")
adapter.UpdateCommand = New SqlCommand("UPDATE CompanyMaster_tbl SET CompanyName = @CompanyName", con.connect)
adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = @dtName,dtPhone = @dtPhone,dtEmail = @dtEmail,[email protected] where [email protected]", con.connect)
adapter.UpdateCommand.Parameters.AddWithValue("@Cid", cid)
adapter.UpdateCommand.Parameters.AddWithValue("@CompanyName", cmpname)
adapter.UpdateCommand.Parameters.AddWithValue("@dtId", dtid)
adapter.UpdateCommand.Parameters.AddWithValue("@dtName", dtname)
adapter.UpdateCommand.Parameters.AddWithValue("@dtPhone", dtPhone)
adapter.UpdateCommand.Parameters.AddWithValue("@dtEmail", dtEmail)
adapter.UpdateCommand.Parameters.AddWithValue("@dtimage", dtimage)
adapter.UpdateCommand.ExecuteNonQuery()
但我得到這一行中的錯誤 dtimage = rv.Row.Field(Of Image)(「empimage」):無法投射類型爲'System.Byte []'的對象以鍵入'System.Drawing。圖片'
異常包含的回答你的問題,你已經創建圖像類型的變量「dtimage」,應聲明此作爲一個字節數組。 – Ramashankar