error while binding datatable to reportviewer table - c#

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.

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) ;

Get Included Rows from DataSource after ReadRecords

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

Insert rows on a existing dataset

I have a dataset called "titulos" and have 1 table there called "tb"
with the columns with the name "titulo","titulo 2" and "titulo3".
I'm trying to do an insertion of rows in the event onclick of a button
but for some reason my code doesn't work!
My dataset is on a xsd file and I am using visual studio 2013 with c#.
I already tried this code but I don't know how to apply in my situation:
NorthwindDataSet.CustomersRow newCustomersRow =
northwindDataSet1.Customers.NewCustomersRow();
newCustomersRow.CustomerID = "ALFKI";
newCustomersRow.CompanyName = "Alfreds Futterkiste";
northwindDataSet1.Customers.Rows.Add(newCustomersRow);
The problem is that shows an error saying it does not recognize the dataset...
The erros is : "The name " Ds_Admissibilidade" does not exist in the current context
A DataSet is a disconnected copy of the data. It forgets if the data originated from database, an xml file or anything else. When you add rows to the DataSet, you only change the in-memory copy, not the original source.
You need some mechanism to update the source. For databases, a table adapter or dataadapter will do this for you. For a file source, you need to serialize the DataSet to the file, much the reverse of the way you read in in first place.
Hope this helps :)
DataRow newRow = titulos.Tables["tb"].NewRow();
newRow["titulo1"] = "titulo1";
newRow["titulo2"] = "titulo2";
newRow["titulo3"] = "titulo3";
titulos.Tables["tb"].Rows.Add(newRow);
Make sure you're setting all the values of the non nullable parameters. If you're using another instance of the dataset "titulos" use ImportRow instead of Add function.

Display DataTable content in ReportViewer

I've heard that the best way to print a DataTable is to use ReportViewer. However I found it more difficult to achieve this than I thought. I am not familiar with ReportViewer, so perhaps I want to find a solution that is non-existent.
"reportView" is the ReportViewer control.
//I am creating a fresh new DataTable here.
DataTable reportDT = new DataTable();
reportDT.TableName = "reportDT";
DataColumn dataColID = reportDT.Columns.Add("ID");
DataColumn dataColValue = reportDT.Columns.Add("Value");
DataRow newrow = reportDT.NewRow();
newrow["ID"] = string1;
newrow["Value"] = string2;
reportDT.Rows.Add(newrow);
//Until now, this works perfectly with DataGridView.
//I am creating a new source object, hopefully from my datatable.
ReportDataSource source = new ReportDataSource("reportDT", reportDT);
reportView.ProcessingMode = ProcessingMode.Local;
reportView.LocalReport.DataSources.Add(source);
this.reportView.RefreshReport();
Running the app like this throws no exception, but it shows no data in the reportview either. It says: "The source of the report definition has not been specified".
I have realized that it might need a .rdlc file, which must be created design time. But if I create it design time, it wants me to fill it with data, which I cannot do, because the data is created runtime. So I want to display a bunch of data in ReportViewer, but the above code does not work. What is wrong with it?
You need to create a report file. The reportViewer1 is a Control, not a Report and therefore cannot display data directly.
To avoid repeating code, your answer can be found here.

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