Help with Crystal Reports [modified]
-
Hi. I'm rather new to asp.net and even more so in crystal. Basically this is the first time I'm using this. What I need to do is prepare a report from a dynamically created dataset(untyped if you will). I have read a lot of articles online but haven't been able to make it work. Basically the table that i want to display in crystal doesn't exist in database and was created programmatically as a DataTable The data simply doesn't display.Here's the code in codebehind: Protected Sub CrystalReportViewer1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Init Dim rpt As New ReportDocument rpt.Load(Server.MapPath("CrystalReport1.rpt") rpt.SetDataSource(dset.Tables("Tab1")) CrystalReportViewer1.ReportSource = rpt CrystalReportViewer1.DataBind() End Sub Please note that the dataset is populated correctly as i can see it in a gridview. CrystalReport1.rpt uses the same schema as Tab1 but using a dataset included at design time called "DataSet1". Here is the code for how this dataset was created: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try Dim mysqlDad As MySqlDataAdapter Dim mysqlConn As MySqlConnection Dim query As String = "" 'some select query that returns 2 rows. Dim connstring As String = "Database=ocsweb;Data Source=10.135.158.160;User Id=abc;Password=abc" dset = New DataSet("Home") dset.ReadXmlSchema(Server.MapPath("~\App_Code\DataSet1.xsd")) mysqlConn = New MySqlConnection(connstring) mysqlDad = New MySqlDataAdapter(query, mysqlConn) mysqlDad.Fill(dset, "Tab1_tmp") Dim Dt As New DataTable("Tab1") Dim col1 As New DataColumn("Unchecked") Dim col2 As New DataColumn("Checked") Dt.Columns.Add(col1) Dt.Columns.Add(col2) Dim dr As DataRow = Dt.NewRow() dr.Item(0) = dset.Tables("Tab1_tmp").Rows(0).Item(0) dr.Item(1) = dset.Tables("Tab1_tmp").Rows(1).Item(0) Dt.Rows.Add(dr) dset.Tables.Add(Dt) catch ex as exception msgbox(ex.message) end try If there is something else that can/needs to be done, please let me know. I'm very new and could surely use some help here. :(
modified on Friday, August 28, 2009 6:18 AM
-
Hi. I'm rather new to asp.net and even more so in crystal. Basically this is the first time I'm using this. What I need to do is prepare a report from a dynamically created dataset(untyped if you will). I have read a lot of articles online but haven't been able to make it work. Basically the table that i want to display in crystal doesn't exist in database and was created programmatically as a DataTable The data simply doesn't display.Here's the code in codebehind: Protected Sub CrystalReportViewer1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Init Dim rpt As New ReportDocument rpt.Load(Server.MapPath("CrystalReport1.rpt") rpt.SetDataSource(dset.Tables("Tab1")) CrystalReportViewer1.ReportSource = rpt CrystalReportViewer1.DataBind() End Sub Please note that the dataset is populated correctly as i can see it in a gridview. CrystalReport1.rpt uses the same schema as Tab1 but using a dataset included at design time called "DataSet1". Here is the code for how this dataset was created: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try Dim mysqlDad As MySqlDataAdapter Dim mysqlConn As MySqlConnection Dim query As String = "" 'some select query that returns 2 rows. Dim connstring As String = "Database=ocsweb;Data Source=10.135.158.160;User Id=abc;Password=abc" dset = New DataSet("Home") dset.ReadXmlSchema(Server.MapPath("~\App_Code\DataSet1.xsd")) mysqlConn = New MySqlConnection(connstring) mysqlDad = New MySqlDataAdapter(query, mysqlConn) mysqlDad.Fill(dset, "Tab1_tmp") Dim Dt As New DataTable("Tab1") Dim col1 As New DataColumn("Unchecked") Dim col2 As New DataColumn("Checked") Dt.Columns.Add(col1) Dt.Columns.Add(col2) Dim dr As DataRow = Dt.NewRow() dr.Item(0) = dset.Tables("Tab1_tmp").Rows(0).Item(0) dr.Item(1) = dset.Tables("Tab1_tmp").Rows(1).Item(0) Dt.Rows.Add(dr) dset.Tables.Add(Dt) catch ex as exception msgbox(ex.message) end try If there is something else that can/needs to be done, please let me know. I'm very new and could surely use some help here. :(
modified on Friday, August 28, 2009 6:18 AM
Try with button click event instead of pageload to bind the dataset to report and see