Solved

Dataset in Datagrid used as Datasource for Crystal Reports

Posted on 2009-05-04
5
917 Views
Last Modified: 2013-11-08
I have a Dataset being filled by code and filling a Datagrid which the user can remove items from the list.  Now I want to take the new Dataset to run a Crystal Report.  Now it works with a fresh dataset set but once I remove one row and click the refresh button on the report it errors out on me.

To test to dataset edits I have a 2nd datagrid that looks at the dataset and refreshes when item is removed from main datagrid.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        oConn.sCommand = "SELECT v_8130.ship_station, v_8130.CUSTNUM, v_8130.CITY, v_8130.SALESORD, v_8130.ENP_NO, v_8130.carton_no, v_8130.ship_to_country, v_8130.ship_to_name, v_8130.ship_to_addr_1, v_8130.ship_to_addr_4, v_8130.ship_gate, v_8130.WEIGHT FROM [501].dbo.v_8130 v_8130 WHERE (v_8130.ship_station = 0) AND v_8130.CUSTNUM = 85101 GROUP BY v_8130.CUSTNUM, v_8130.SALESORD, v_8130.CITY, v_8130.ENP_NO, v_8130.carton_no, v_8130.ship_to_country, v_8130.ship_to_name, v_8130.ship_to_addr_1, v_8130.ship_to_addr_4, v_8130.ship_gate, v_8130.ship_station, v_8130.WEIGHT"
        dset1 = oConn.executeQueryReturnDS()
        dtable1 = dset1.Tables(0)
        dtable1.TableName = "fill"
        DataGrid1.DataSource = dtable1
        DataGrid1.Refresh()
        oConn.close()
 
    End Sub
 
    Private Sub DataGrid1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.CellClick
        If DataGrid1.CurrentCell.ColumnIndex = 0 Then
            DataGrid1.Rows.Remove(DataGrid1.CurrentRow)
        End If
 
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DataGrid2.DataSource = dtable1
        DataGrid2.Refresh()
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim cr As Report1 = New Report1
        dtable = dtable1
        cr.SetDataSource(dtable)
        CrystalReportViewer1.ReportSource = cr
        CrystalReportViewer1.Refresh()
 
    End Sub

Open in new window

0
Comment
Question by:kwitcom
  • 2
  • 2
5 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 24300192
THe report is actually working on a copy and probably doesn't get the deletes.

Since you are assigning the dataset why do you need the refresh?

mlmcc
0
 

Author Comment

by:kwitcom
ID: 24300385
The dataset is not set to the report until the report button is pressed.  If I press it at the start without deleting any rows it works fine.  When I delete from the dataset then click the button to create the report it gets errors.  Now I created a 2nd datagrid to confirm the dataset is working correctly when i do the deletes.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24300513
You may need to refresh the dataset before assigning it to the report.

You might check this link.  The dataset is built in code then attached to the report
http://www.businessobjects.com/global/pdf/dev_zone/VS2005_Walkthroughs.pdf

mlmcc
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 24301038
have you tried to call AcceptChanges on your Dataset/Datatable before calling SetDataSource?
0
 

Author Comment

by:kwitcom
ID: 24303927
The AcceptChanges worked.  Thanks for all your help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question