本文介绍了错误! Nable将'system.object'类型的对象强制转换为'system.byte []'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿朋友们。我试图通过CellClick事件从DataGridView访问数据。在 VB .NET 我什么时候单击单元格我从表格中获取所有数据但不能在PictureBox中查看图像。 当我只尝试此代码时: pic1 = selectedRow.Cells( 13 )。价值 Dim ms As 新 MemoryStream(pic1 ) pb_stud_pic.Image = Image.FromStream(ms)我收到错误!无法转换'system.object'类型的对象来输入'system.byte []' 然后我尝试下面的代码: 但是我没有在图片框中获取图像.. 我尝试了什么: 私人 Sub DataGridView1_CellClick(发件人作为系统。对象,e As System.Windows.Forms.DataGridViewCellEventArgs)句柄 DataGridView1.CellClick 尝试 Dim index As 整数 = e.RowIndex Dim selectedRow As 新 DataGridViewRow() selectedRow = DataGridView1.Rows(index) txt_stud_no.Text = selectedRow.Cells( 0 )。Value.ToString() txt_stud_name.Text = selectedRow.Cells( 1 )。Value.ToString() dtp_stud_dob.Value = selectedRow.Cells( 2 )。Value.ToString() txt_stud_gender.Text = selectedRow.Cells( 3 )。Value.ToString() 如果 txt_stud_gender.Text = 男 然后 rdo_male.Checked = 真 其他 rdo_female.Checked = True 结束 如果 cb_stud_blood.Text = selectedRow.Cells( 4 )。Value.ToString() txt_stud_add.Text = selectedRow.Cells( 5 )。Value.ToString() txt_stud_city.Text = selectedRow.Cells( 6 )。值。 ToString() txt_stud_pc.Text = selectedRow.Cells( 7 )。Value.ToString() txt_stud_mob.Text = selectedRow.Cells( 8 )。Value.ToString() cb_adyear.Text = selectedRow.Cells( 9 )。 Value.ToString() cb_cbranch.Text = selectedRow.Cells( 10 )。Value.ToString() txt_stud_email.Text = selectedRow.Cells ( 11 )。Value.ToString() cb_csem.Text = selectedRow.Cells( 12 ).Value.ToString() con。 Open() dr = cm.ExecuteReader() 如果 dr.Read()那么 如果 不 dr.IsDBNull(dr.GetOrdinal( 图像))然后 pic1 = CType (dr( Image), 字节()) pic1 = selectedRow.Cells( 13 )。价值 pic1 = ds.Tables( 学生)。行(i)( 13 ) 如果 不(pic1 Nothing )然后 Dim ms As 新 MemoryStream(pic1) pb_stud_pic.Image = Image.FromStream(ms) 其他 pb_stud_pic.Image = 没什么 结束 如果 结束 如果 结束 如果 con.Close() Catch ex As 异常 MessageBox.Show( 错误!& ex.Message) con.Close() 结束 尝试 结束 Sub 解决方案 Convert.ToByte Method(Object)(System) [ ^ ] Hey Friends. I Am Trying To Access Data From DataGridView To Form By CellClick Event. In VB .NETWhen Ever I Click On Cell I Got All Data From Table To Form But Not Able To See Image In PictureBox.When I Tried Only This Code:pic1 = selectedRow.Cells(13).ValueDim ms As New MemoryStream(pic1)pb_stud_pic.Image = Image.FromStream(ms)I Got Error! unable to cast object of type 'system.object ' to type 'system.byte[]'Then I Try Below Code:but Then I Dont Get Image in picture Box..What I have tried:Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Try Dim index As Integer = e.RowIndex Dim selectedRow As New DataGridViewRow() selectedRow = DataGridView1.Rows(index) txt_stud_no.Text = selectedRow.Cells(0).Value.ToString() txt_stud_name.Text = selectedRow.Cells(1).Value.ToString() dtp_stud_dob.Value = selectedRow.Cells(2).Value.ToString() txt_stud_gender.Text = selectedRow.Cells(3).Value.ToString() If txt_stud_gender.Text = "Male" Then rdo_male.Checked = True Else rdo_female.Checked = True End If cb_stud_blood.Text = selectedRow.Cells(4).Value.ToString() txt_stud_add.Text = selectedRow.Cells(5).Value.ToString() txt_stud_city.Text = selectedRow.Cells(6).Value.ToString() txt_stud_pc.Text = selectedRow.Cells(7).Value.ToString() txt_stud_mob.Text = selectedRow.Cells(8).Value.ToString() cb_adyear.Text = selectedRow.Cells(9).Value.ToString() cb_cbranch.Text = selectedRow.Cells(10).Value.ToString() txt_stud_email.Text = selectedRow.Cells(11).Value.ToString() cb_csem.Text = selectedRow.Cells(12).Value.ToString() con.Open() dr = cm.ExecuteReader() If dr.Read() Then If Not dr.IsDBNull(dr.GetOrdinal("Image")) Then pic1 = CType(dr("Image"), Byte()) pic1 = selectedRow.Cells(13).Value pic1 = ds.Tables("Student").Rows(i)(13) If Not (pic1 Is Nothing) Then Dim ms As New MemoryStream(pic1) pb_stud_pic.Image = Image.FromStream(ms) Else pb_stud_pic.Image = Nothing End If End If End If con.Close() Catch ex As Exception MessageBox.Show("Error!" & ex.Message) con.Close() End Try End Sub 解决方案 Convert.ToByte Method (Object) (System)[^] 这篇关于错误! Nable将'system.object'类型的对象强制转换为'system.byte []'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-22 11:21