Amber Green
Amber Green

Reputation: 3

Datatable items not showing in Crystal Report

So I have a project in vs2010 and tried to use Crystal Report to print a receipt. I have this listview where all the items being purchased are displayed and those items will be send to the Cyrstal Report via DataSet's DataTable but it wont show. Please someone tell me what is wrong with my code.

rpt design

enter image description here

rpt Output not showing the list from listview

enter image description here

    Private Sub orForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myOR As New salesReceipt
        Dim cashier As TextObject = myOR.ReportDefinition.ReportObjects("Text11")
        Dim dtm As TextObject = myOR.ReportDefinition.ReportObjects("Text12")

        Dim ds As New DataSet
        Dim dt As New DataTable
        ds.Tables.Add(dt)
        With dt
            .Columns.Add("Items")
            .Columns.Add("Quantity")
            .Columns.Add("Total")
        End With
        For i As Integer = 0 To main.lvItemsToPurchase.Items.Count - 1
            Dim dr As DataRow = dt.NewRow
            dr("Items") = main.lvItemsToPurchase.Items.Item(i).SubItems(1).Text
            dr("Quantity") = main.lvItemsToPurchase.Items.Item(i).SubItems(3).Text
            dr("Total") = main.lvItemsToPurchase.Items.Item(i).SubItems(5).Text
            dt.Rows.Add(dr)
        Next

        cashier.Text = "Cashier: " & curUser
        dtm.Text = "Date/Time: " & Format(Now, "MMMM dd, yyyy") & " " & FormatDateTime(Now, DateFormat.LongTime)
        myOR.SetDataSource(ds)
        CrystalReportViewer1.ReportSource = myOR
    End Sub

Upvotes: 0

Views: 637

Answers (1)

Vivek S.
Vivek S.

Reputation: 21885

Use myOR.SetDataSource(ds.Tables(0)), A dataset contains more than one datatable so you should specify the datatable in a dataset

Upvotes: 1

Related Questions