Get Included Rows from DataSource after ReadRecords - c#

Is it possible to read which records were included in a report after the selection formula is applied via ReadRecords?
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(#"report.rpt");
DataSet reportDataSet = new DataSet();
reportDataSet.ReadXml(#"data.xml");
reportDocument.SetDataSource(reportDataSet);
reportDocument.ReadRecords();
reportDocument.Rows.Count returns the correct number of rows. However, the only column in the CrystalReportDataRowView available is "RecordNumber", and not any of the columns provided by the data source.

If you are map physical database object, then you will be get the records count with column value.
But as you are assign xml data, so crystal report will does not give you any thing, because all are runtime set and render by Crystal report.
Please read below link the understand the logic of crystal report with datasource "
Reading CrystalReport's Field Value Programmically

Related

How to capture project level data-set in another windows form or crystal report form c#

I have used a dataset in many of my windows forms for datagrid. As you can see i have project level dataset created.
The problem is i would liek to resume that dataset inside code to assing source for crystal report as follow.
//sbmsDataSetAllis not recognized
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("rystalReport1.rpt");
cryRpt.SetDataSource(sbmsDataSetAll.Tables["recent_slide_dataset"].DataSet) ;
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
OK, but you need to understand that these dataset items you see in the solution explorer are representing class types(things you can create) not object instances(things you have created) so you can only use object instances in your code
On the form where your dataset is created, with some code like
sbmsDataSetAll myDataset = new sbmsDatasetAll();
is where the instance of the dataset is. It is only on this form's code that you can link it to the report unless you have passed the dataset to another place via method parameters.
You should really pass one of the tables inside the dataset as the crystal report datasource, unless you already told crystal what table name to use (in design mode somewhere - I can't see it in your code). When you work with strongly typed datasets like these you don't need to use the .Tables collection. Every table in the set has a named property for the table:
cryRpt.SetDataSource(sbmsDataSetAll.recent_slide_dataset) ;
You also don't need to call a table's DataSet Property because that just points back to the dataset the table is in, which you already know when you chose the table:
cryRpt.SetDataSource(sbmsDataSetAll) ;
As another small critique, in c# we use PascalCase of object, property and method names, so your dataset entities should really be named like:
cryRpt.SetDataSource(SbmsDataSetAll.RecentSlides) ;

Cast a single database record to Dataset for embeded SSRS report

I'm trying to embed a local SSRS report into my MVC razor page for the very first time. I created a simple report to prove my concept, an .rdlc file. The report has a couple text boxes, logo and a couple tables.
With no tables and no datasets, I can get the report to run in the MVC view without issue. When I add the first dataset, the trouble begins as I cannot seem to come up with the correct way to pass data from my controller to the report.
Part of my problem, it seems ReportDataSource prefers an IEnumerable such as a list. In order to display a name and address at the top of the report, I don't need a list of objects, just one object, or a single database row. How can I pass this object as a datasource / dataset?
Here is my current controller code:
ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + #"Reports\AnnualFeeStatement_DRAFT.rdlc";
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", UserDAL.getMember("Simons", "12345", "1988")));
ViewBag.ReportViewer = reportViewer;
return View();

crystal report datetime field does not show but has value c#

I have a crystal report in which I used datasets to display values. The data set is filled from view(sql view) retrieved in data connection (table adapter, data table)_. All fields are displaying except for the one field which is datetime. I have tried every possible way but not working. I am at my wits end.
I tried converting it to string both in sql itself in view design
and in dataset.
I casted it using ToText() and put it in formula but keeps returning
error 'field not known'. I was thinking I might have dropped the field but I already re added the dataset, data table and adapter and made sure I clicked the "verify database" and the field is there!
I tried debugging the code to make sure the value is being pulled,
and yes it is.
I "preview data" the datatable in dataset by right clicking it and
clicking preview data and yes it shows the field has value. All
fields are displaying
I tried making the field in the dataset properties as string(before
I changed datetime type to string)
But why is it not showing in the report itself. :(. any idea or other suggestion I can try to make it show?
public void loadReport(bool loadAll)
{
AirDataAccess ada = new AirDataAccess();
List<AirData> alist= ada.GetRowLogAllView();
ReportUrl = #"~\Reports\RawLogData.rpt";
reportDocument.Load(Server.MapPath(ReportUrl));
reportDocument.SetDataSource(alist);
CrystalReportViewer1.DataBind();
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.ReportSource = reportDocument;
}

error while binding datatable to reportviewer table

I have filled datatable. I want to display it in the report. I'm doing like this:
ReportDataSource source = new ReportDataSource("dtss", dt);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(source);
ReportViewer1.DataBind();
ReportViewer1.LocalReport.Refresh();
But when i try to build, i get error:
The dataset ‘DataSet1’ refers to the data source “”, which does not exist.
What am I missing? Using Webforms(ASP.net)
The name that you give your ReportDataSource needs to match the name of the DataSet (defined within the report). For example, on line 1 (of your code, above) you need to say:
ReportDataSource source = new ReportDataSource("DataSet1", dt);
or rename the dataset (in your report) to "dtss"
Alternative.
Apparently if you add a DataSet within the rdlc file it auto associates the name in the xml, and when you delete that from the rdlc it doesn’t remove it from the xml, so it just gives you a reference which it thinks of as an empty dataset, and cannot evaluate. I first named my second one DataSet2 and then after setting it up in the design decided to delete it and rename it, but you have to go back to the xml and delete the entire empty DataSet node<>.
Hope this helps someone who's problems cannot be solved by the above answer.

Is that possible to bind two dataset at a same time in crystal report?

Is that possible to bind two dataset at a same time in asp.net crystal report?
I tried the code below, but it asks for server details:
Invoice inv = new Invoice();
inv.OrgId = Session["org_id"].ToString();
inv.InvoiceId = invoiceId.ToString();
ds = _reportController.ReportPrintBillView(inv);
dtBill=ds.Tables[0];
dtInvoice = ds.Tables[1];
ReportDocument myRpt = new ReportDocument();
myRpt.Load(Server.MapPath("PrintandprintBill.rpt"));
myRpt.SetDatabaseLogon("root", "root", "localhost", "hemaepdb");
myRpt.SetDataSource(dtBill);
myRpt.SetDataSource(dtInvoice);
CrystalReportViewerPrint.ReportSource = myRpt;
CrystalReportViewerPrint.Visible = true;
No, the report accepts one datasource. However your subreports may have a different datasource.
EDIT:
If you need data from two different datasets that have similar data you might try to combine the data into one dataset. Even if some of the data duplicates, you can then create groups and use the suppress functionality to only show and format the data in the way you need to see it. See my answer here for a better explanation of the grouping and suppressing that I am referring to.
From ur Requirement i think u want to use View. View is one kind of logical table that maps other columns from different tables. And at Datable just use View Name and add this datatable to dataset. simply SetDataSource to dataset.

Categories