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;
}
Related
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) ;
I have build crystal report with vs 2013 and I did the following
add the database fields for the tables I need.
I am calling the report from form1 and it display the data
so it is good but what I need to is
get an ID from textbox in the form1 and pass it as parameter to report
so it display a specific record from database fields, so I made a parameter called P_PatientID and pass it to report below is the code I am using on form_load to call the crystal report and pass the parameter P_PatientID
private void F0118_Load(object sender, EventArgs e)
{
string RepPath = Application.StartupPath + #"\REP0100.rpt";
ReportDocument rep = new ReportDocument();
rep.Load(RepPath);
rep.SetParameterValue("P_PatientID", vPatientID);
RepViewer.ReportSource = rep;
rep.Refresh();
}
what I need to know is
is the parameter should be static or dynamic list of values?
do I have to set a default value for it ?
I do not want to display the prompt that asks for the parameter value on run time
What I have to do to link that parameter to database fields I display on report so data in report are related to the ID entered by user in form1 textbox?
finally there is no more code to show I post all codes I write for this the reset of things I made throw wizards there is n coding
please help and thanks alot
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
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.
This is my first time working with DataSets and BindingSources, so please be gentle on me.
As part of a more complicated reporting system (I've distilled it down to a basic incarnation, but it still won't run correctly), I'm trying to pull data from a database using a DataSet problematically (that is, not set up via the designer). Here is the code I have so far:
// pull the data set
var dsReportData = new Reports2.ReportTest2();
dsReportData.BeginInit();
dsReportData.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
// bind tha data set
BindingSource bsReportBinding = new BindingSource();
((ISupportInitialize)bsReportBinding).BeginInit();
bsReportBinding.DataMember = dsReportData.Tables[0].TableName;
bsReportBinding.DataSource = dsReportData;
bsReportBinding.ResetBindings(true);
// test this stuff
dgvTester.DataSource = bsReportBinding;
dsReportData.EndInit();
((ISupportInitialize)bsReportBinding).EndInit();
I based this on the code I saw in a .designer.cs file after setting up binding through the designer. dgvTester is just a DataGridView with the default properties created in the designer.
The ReportTest2 dataset has just one TableAdapter in it, added via designer.
Now, if I went to Data -> Preview Data in VS and previewed the ReportTest2.payments.Fill,GetData () object, it returns data just fine, same as if I ran the query I used to crate the TableAdapter in SQL Server Management Studio.
However, running the actual code results in the DataGridView getting the column names from the query result, but not the actual data. The debugger reveals that dsReportData.payments.Rows.Count == 0 (and that, yes, dsReportData.Tables[0] is payments).
I ultimately intend to use the BindingSource to provide data to a ReportViewer, but first things first is making sure there's no problems with retrieving the data before going onto debug the report.
Hopefully I'm missing something obvious here. I hope so...
Figured it out after some trial and error. This is the part I was missing:
var TableAdapter = new Reports2.ReportTest2TableAdapters.paymentsTableAdapter();
TableAdapter.Fill(dsReportData.payments);
I didn't see it in the code I was referencing because the designer snuck it into the .cs file instead of the .designer.cs file. This made the data appear.