编辑后保存图像,该时间仅保存winform应用程序中的最后编辑图像

时间:2014-01-21 12:23:51

标签: vb.net winforms datagridview

我正在处理Windows窗体应用程序。我有GridView这样的: enter image description here

在单元格内容中单击我编写的代码如下:

If e.ColumnIndex = 4 Then
            Dim OFDLogo As New OpenFileDialog()
            OFDLogo.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp"
            If OFDLogo.ShowDialog() = DialogResult.OK Then
                gv.Rows(e.RowIndex).Cells(6).Value = Image.FromFile(OFDLogo.FileName)
            End If
        End If

并保存按钮我写了这样的代码:

Dim cmpny As String = "Delete from CompanyMaster_tbl"
        Exetransaction(cmpny)
    For i As Integer = 0 To gv.RowCount - 2
     sqlInsertT2 = "Insert Into DepartmentMaster_tbl(dtname,dtphone,dtEmail,Cid) Values ('" + myTI.ToTitleCase(gv.Rows(i).Cells(1).Value) + "','" + gv.Rows(i).Cells(2).Value + "','" + gv.Rows(i).Cells(3).Value + "'," & Ccid & ");"
                    Exetransaction(sqlInsertT2)
                    Dim departmnt As String = gv.Rows(i).Cells(1).Value

                    Dim departid As Integer = RecordID("dtId", "DepartmentMaster_tbl", "dtName", departmnt)
                    Dim sql As String

                    '----------------------------------

                    Dim image As Image = TryCast(gv.Rows(i).Cells(4).Value, Image)
                    If image IsNot Nothing Then
                        Dim ms As New MemoryStream()
                        image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
                        Dim imagedata As Byte() = ms.ToArray()
                        sql = "update DepartmentMaster_tbl set empimage=@photo where dtId='" & departid & "'"
                        Dim cmd As New SqlCommand(sql, con.connect)
                        cmd.Parameters.Add("@photo", SqlDbType.Image)
                        cmd.Parameters("@photo").Value = imagedata
                        cmd.ExecuteNonQuery()
                        con.disconnect()
                    End If
     Next

我第一次尝试保存这个,保存两个图像,再次加载同一页面后我编辑了一个图像并尝试保存,但那个时间只保存编辑过的图像我的代码有什么问题?

In cell content click I am taking row_index

0 个答案:

没有答案