我有像这样的数据网格视图。我使用数据源绑定填充数据网格视图
虽然绑定我得到一个额外的列emp图像..实际上我想在 image
列本身显示我的图像..所以我在加载事件中给出了这样的代码
Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage from CompanyMaster_tbl c join DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)
dt1 = New DataTable
bSource = New BindingSource
adapter.Fill(dt1) 'Filling dt with the information from the DB
bSource.DataSource = dt1
gv.DataSource = bSource
gv.Columns("cid").Visible = False
gv.Columns("dtId").Visible = False
Dim img As New DataGridViewImageColumn
img.HeaderText = "image"
gv.Columns.Insert(6, img)
For i As Integer = 0 To gv.Rows.Count - 1
gv.Rows(i).Cells(6).Value = gv.Rows(i).Cells(7).Value
Next
gv.Columns("empimage").Visible = False
actullay在这里我将图像从empimage
列复制到image
列,然后使empimage
可见false ..保存后我再次调用此方法..那时候得到的错误就像这样:
答案 0 :(得分:0)
而不是执行以下三个步骤
image
列empimage
列复制到image
列empimage
列不要添加图像列并更改查询以为empimage列指定别名,如下所示
选择c.cid,c.CompanyName,d.dtId,d.dtName作为Department,d.dtPhone作为Phone,d.dtEmail作为Email,d.empimage作为图像来自CompanyMaster_tbl c加入DepartmentMaster_tbl d on c.Cid = d.cId by cid