无法从vb.net windows窗体应用程序中的数据网格视图更新图像

时间:2014-01-22 09:17:38

标签: c# vb.net winforms datagridview

我在vb.net windows应用程序中有一个数据网格视图,我正在填充网格视图,如下所示: 我在这样的负载中编写代码

 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

在更新按钮中,我写了这样的代码:

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")

            Using ms As New MemoryStream(rv.Row.Field(Of Byte())("empimage"))
                dtimage = New Bitmap(ms)
            End Using

            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,empimage=@dtimage  where dtId=@dtid", 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()
        Next

执行此操作时,我在此行中收到错误: adapter.UpdateCommand.ExecuteNonQuery() 错误:No mapping exists from object type System.Drawing.Bitmap to a known managed provider native type

我的代码出了什么问题 任何帮助都很明显??

0 个答案:

没有答案