1.ต้องการให้ field เปล่าที่ไม่มีภาพหายไปค่ะ
ด้านล่างเป็นโค้ดที่ใช้ get ภาพจาก Datagrid มาใส่ Dataset
Code (VB.NET)
For j = 0 To chkSel.GetUpperBound(0) - 1
For i As Integer = 0 To grdResultAnalysis.Rows.Count - 2
If grdResultAnalysis.Rows(i).Cells(2).Value.ToString = chkSel(j) Then
If grdResultAnalysis.Rows(i).Cells(4).GetType.ToString = "System.Windows.Forms.DataGridViewTextBoxCell" Then
dsEx.dtTest.Rows.Add(number, grdResultAnalysis.Rows(i).Cells(5).Value, Nothing)
Else
Dim msPic As New MemoryStream
Dim bmp As Bitmap
Dim picByte As Byte()
bmp = grdResultAnalysis.Rows(i).Cells(4).Value
bmp.Save(msPic, System.Drawing.Imaging.ImageFormat.Jpeg)
picByte = msPic.GetBuffer()
bmp.Dispose()
dsEx.dtTest.Rows.Add(countNum, grdResultAnalysis.Rows(i).Cells(5).Value, picByte)
msPic.Close()
End If
For k = 0 To crystalRow - 1
If grdResultAnalysis.Rows(i).Cells(4).GetType.ToString = "System.Windows.Forms.DataGridViewTextBoxCell" Then
dsEx.dtTest.Rows.Add("", grdResultAnalysis.Rows(i + k + 1).Cells(5).Value, Nothing)
Else
Dim msPic As New MemoryStream
Dim bmp As Bitmap
Dim picByte As Byte()
bmp = grdResultAnalysis.Rows(i + k + 1).Cells(4).Value
bmp.Save(msPic, System.Drawing.Imaging.ImageFormat.Jpeg)
picByte = msPic.GetBuffer()
bmp.Dispose()
dsEx.dtTest.Rows.Add("", grdResultAnalysis.Rows(i + k + 1).Cells(5).Value, picByte)
msPic.Close()
End If
Next
number += 1
i += crystalRow
End If
Next
Next
Dim reportTest As New reportTestForm
Dim crt As New crsReportTest
crt.SetDataSource(dsEx)
reportTest.CrystalReportViewer1.ReportSource = crt
reportTest.Show()