简体   繁体   中英

how to add image to dataset in vb?

i have method image bar code in vb i want to save image bar code into dataset ? in frm_Reporting, i have crystal report viewer and put barcodeImage,when btnEncode is calling, image barcode is created, then must to insert to data set .

Private Sub Frm_Reporting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CrystalReportViewer1.ReportSource = Nothing
        Dim rptbarcode As RptPacking
        rptbarcode = New RptPacking
        Dim xrep As DataSet1
        xrep = New DataSet1
        Dim row As DataRow
        Dim MyImg As Image = Nothing
        Try
            btnEncode(MyImg, BarcodeText)
            row = xrep.Tables(0).NewRow
            xrep.Tables("DataTable1").Rows(0).SetAdded = MyImg
            CrystalReportViewer1.ReportSource = rptbarcode
            rptbarcode.SetDataSource(xrep)
            rptbarcode.PrintToPrinter(1, False, 0, 0)
        Catch ex As Exception
        End Try     
    End Sub

 Private Sub btnEncode(ByRef pic As Image, ByVal txtData As String)
        Dim W As Integer = 160
        Dim H As Integer = 110
        Dim b As BarcodeLib.Barcode
        Dim type As BarcodeLib.TYPE = BarcodeLib.TYPE.UNSPECIFIED
        type = BarcodeLib.TYPE.CODE128
        b = New BarcodeLib.Barcode()
        Try
            If type <> BarcodeLib.TYPE.UNSPECIFIED Then
                b.IncludeLabel = True

                '===== Encoding performed here ===== 
                pic = b.Encode(type, txtData, W, H)
                'CType(Frm, frm_submitentery).pic_img.Image = pic.Image
                '=================================== 


            End If

        Catch ex As Exception
            'try 
            MessageBox.Show(ex.Message)
            'catch 
        End Try

    End Sub

您可以将图像存储在虚拟目录中,然后使用文件流将其转换为字节数组

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM