locked
Problem with dataSet when use as report source RRS feed

  • Question

  • Hello everyone, I'm new to the group.

    I have used dataSet as report source and I use Crystal Activex Report Viewer to my report. Also, I have notice that when I run the program once it got error. When I try again, it run properly. If I run again, it got error. It happen like this repeatedly.

    The error statement is the statement that I assign dataSet as Report Source.

    Here is the error.

    " Attempted to read or write protected memory. This is often an indication that other memory is corrupt. "

    Here is the statement that course error:

    Report.Database.SetDataSource(myDataSetBooking.Tables(1))

    I'm using Visual Studio 2008 and  "Crystal Activex Report Viewer" as report viewer.

    Please, help!!!!!!!!!

    -----------------------Below is the completed code---------------------------

            

    Private Sub btnpreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpreview.Click
            If usefulness.CheckNull(cbocustomername, cbogender, txtaddress, mtbphone, cboroomtype, cboroomnumber, txtprepaid) Then Exit Sub
            Dim myTable As DataTable = myDataSetBooking.Tables.Add("Items")
            myTable.Columns.Add("ProductType", GetType(String))
            myTable.Columns.Add("ProductName", GetType(String))
            myTable.Columns.Add("Price", GetType(Double))
            myTable.Columns.Add("Quantity", GetType(Long))
            myTable.Columns.Add("Amount", GetType(Double))
            Dim myRow As DataRow

    'Here just add some data to datatable in dataset

            For i As Integer = 0 To ListView1.Items.Count - 1
                myRow = myTable.NewRow
                myRow(0) = "Food"
                myRow(1) = ListView1.Items(i).SubItems(1).Text
                myRow(2) = ListView1.Items(i).SubItems(3).Text
                myRow(3) = ListView1.Items(i).SubItems(2).Text
                myRow(4) = ListView1.Items(i).SubItems(4).Text
                myTable.Rows.Add(myRow)
            Next
            For i As Integer = 0 To ListView2.Items.Count - 1
                myRow = myTable.NewRow
                myRow(0) = "Beverage"
                myRow(1) = ListView2.Items(i).SubItems(1).Text
                myRow(2) = ListView2.Items(i).SubItems(3).Text
                myRow(3) = ListView2.Items(i).SubItems(4).Text
                myRow(4) = ListView2.Items(i).SubItems(5).Text
                myTable.Rows.Add(myRow)
            Next

            Dim Report As New CRAXDDRT.Report
            Dim Crystal As New CRAXDDRT.Application
            Report = New CRAXDDRT.Report
            Dim fs_Report As String

            fs_Report = "D:\DBRestaurant(Source Codes)\Code\Restaurant\Restaurant\ReportBooking.rpt"
            Report = Crystal.OpenReport(fs_Report)
            Report.DiscardSavedData()
            Report.Database.SetDataSource(myDataSetBooking.Tables(1)) ' Problem happen here.......................................................


            FrmReport.AxCrystalActiveXReportViewer1.ReportSource = Report
            FrmReport.AxCrystalActiveXReportViewer1.ViewReport()
            FrmReport.AxCrystalActiveXReportViewer1.Refresh()
            FrmReport.Show()

        End Sub

    • Moved by Jie Bao Tuesday, May 22, 2012 9:47 AM (From:Visual Basic Express Edition)
    Friday, May 11, 2012 6:52 PM

Answers

All replies

  • Hi HookMM,

    Welcome to the MSDN forum.

    The error is a general one. So I’m afraid that there is no a specific solution to this issue. As I read your code, it seems that some issue about the DataSet. Would you like to share more information about Dataset (myDataSetBooking) and the datatables in it (Pay attention that the number of datatable is 0 based, so myDataSetBooking.Tables(1) is datatable2  )?

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 14, 2012 4:43 AM
  • Thank Mark Liu-Lxf for replying!!

    I think my DataSet is ok because I have used it once already when I used it to bind with 
    the original crystal report viewer. Just wanna tell you that when I work with "crystal report viewer" and this dataset, it works perfectly; however, it doesn't support unicode, so I think my dataset is ok. If I don't use unicode, I can see the result. But I still wanna view my report in unicode, so I switch to use "Crystal Activex Report Viewer" which supports unicode and bind it with my dataset that I have used before. As a result, it works cuz I have see unicode in that report. Although it works but as I have said above, it's some kind of weird thing that I have ever met. After I have finished it, it's ok sometime. I have noticed that when I view my report, if the first time is ok.  Then next time, error can be happen but it doesn't happen. Then,when I view the third time, it must have been an error occur. It looks strange to me and it happens like this again and again. 

    Here I can show you, my previous work. Unlike using Crystal ActiveX Report Viewer, It works perfectly when I used dataset with Crystal Report Viewer. 

     If usefulness.CheckNull(txtcustomername, txtgender, txtaddress, mtbphone, cboroomtype, cboroomnumber, txtroomprice, _
            txtfloor, txtprepaid, txtaddress) Then Exit Sub
            Dim myTable As DataTable = myDataSetCheckOut.Tables.Add("Items")
            myTable.Columns.Add("ProductType", GetType(String))
            myTable.Columns.Add("ProductName", GetType(String))
            myTable.Columns.Add("Price", GetType(Double))
            myTable.Columns.Add("Quantity", GetType(Long))
            myTable.Columns.Add("Amount", GetType(Double))
            Dim myRow As DataRow
            For i As Integer = 0 To lstfood.Items.Count - 1
                myRow = myTable.NewRow
                myRow(0) = "Food"
                myRow(1) = lstfood.Items(i).SubItems(1).Text
                myRow(2) = lstfood.Items(i).SubItems(3).Text
                myRow(3) = lstfood.Items(i).SubItems(2).Text
                myRow(4) = lstfood.Items(i).SubItems(4).Text
                myTable.Rows.Add(myRow)
            Next
            
            Dim objRpt As New CRCheckOut
            objRpt.SetDataSource(myDataSetCheckOut.Tables(1))
            ReportCheckOut.CrystalReportViewer1.ReportSource = objRpt
            ReportCheckOut.CrystalReportViewer1.Refresh()
            ReportCheckOut.Show()

    Sorry for my bad English.

    Monday, May 14, 2012 9:48 AM
  • Hi HookMM,

    As the Crystal ActiveX Report Viewer is a third party control which I’m not familiar with it. I will suggest you try to connect to the official website of Crystal report to find a solution:http://www.sdn.sap.com/irj/scn/advancedsearch?query=Crystal%20ActiveX%20Report%20Viewer

    Hope this helps.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Cor Ligthert Wednesday, May 16, 2012 10:18 AM
    • Marked as answer by Mr. Wharty Thursday, May 31, 2012 3:43 AM
    Wednesday, May 16, 2012 9:20 AM