Creating Reports using DataSet
-
I'm having an access database table which consists of 4 different columns Day, Month, and Year-1 and Year-2 (e.g 22-July-2008 is present in Database as: 07, 22, 20, 08) as columns. So I have added a new Date column in a newly created Dataset which concatenates all these 4 fields and show it as a single date field. But now the problem is that, I'm not getting anywhere with how to link this newly created dataset with my Crystal Report. Thanking you in anticipation. My C#.Net code is as shown below:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
// Code to get data from database
myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\as400.mdb";
myCon.Open();string sqlQuery = "Select \[CLNT#\], CNAME, \[CSS#\], CADMHH, CADMYY, CADMMM, CADMDD, CSEX from SAMFILE\_CLIENTP"; myAdp = new OleDbDataAdapter(sqlQuery, myCon); // Create a Dataset and using DataAdapter to fill it PIN\_DataSet PDS = new PIN\_DataSet(); PDS.Clear(); myAdp.Fill(PDS,"SAMFILE\_CLIENTP"); //START - Added new DataSet for concatenating date fields DataSet newPDS = new DataSet(); newPDS = PDS.Copy(); DataColumn dCol = new DataColumn(newPDS.Tables\[0\].Columns.Add("DT", typeof(String)).ToString()); for(Int32 i = 0; i < newPDS.Tables\[0\].Rows.Count; i++) { DataRow row = newPDS.Tables\[0\].Rows\[i\]; row\["DT"\] = row\["CADMMM"\].ToString() + "/" + row\["CADMDD"\].ToString() + "/" + row\["CADMHH"\].ToString() + row\["CADMYY"\].ToString(); } //END - Added new DataSet for concatenating date fields // Create a CrystalReport1 object PIN\_Crystal\_Report myReport = new PIN\_Crystal\_Report(); // Set the DataSource of the report myReport.SetDataSource(PDS); // Set the Report Source to ReportView crystalReportViewer1.ReportSource = myReport; } catch(Exception obj) { MessageBox.Show(obj.Message, "X'eption"); }
}
-
I'm having an access database table which consists of 4 different columns Day, Month, and Year-1 and Year-2 (e.g 22-July-2008 is present in Database as: 07, 22, 20, 08) as columns. So I have added a new Date column in a newly created Dataset which concatenates all these 4 fields and show it as a single date field. But now the problem is that, I'm not getting anywhere with how to link this newly created dataset with my Crystal Report. Thanking you in anticipation. My C#.Net code is as shown below:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
// Code to get data from database
myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\as400.mdb";
myCon.Open();string sqlQuery = "Select \[CLNT#\], CNAME, \[CSS#\], CADMHH, CADMYY, CADMMM, CADMDD, CSEX from SAMFILE\_CLIENTP"; myAdp = new OleDbDataAdapter(sqlQuery, myCon); // Create a Dataset and using DataAdapter to fill it PIN\_DataSet PDS = new PIN\_DataSet(); PDS.Clear(); myAdp.Fill(PDS,"SAMFILE\_CLIENTP"); //START - Added new DataSet for concatenating date fields DataSet newPDS = new DataSet(); newPDS = PDS.Copy(); DataColumn dCol = new DataColumn(newPDS.Tables\[0\].Columns.Add("DT", typeof(String)).ToString()); for(Int32 i = 0; i < newPDS.Tables\[0\].Rows.Count; i++) { DataRow row = newPDS.Tables\[0\].Rows\[i\]; row\["DT"\] = row\["CADMMM"\].ToString() + "/" + row\["CADMDD"\].ToString() + "/" + row\["CADMHH"\].ToString() + row\["CADMYY"\].ToString(); } //END - Added new DataSet for concatenating date fields // Create a CrystalReport1 object PIN\_Crystal\_Report myReport = new PIN\_Crystal\_Report(); // Set the DataSource of the report myReport.SetDataSource(PDS); // Set the Report Source to ReportView crystalReportViewer1.ReportSource = myReport; } catch(Exception obj) { MessageBox.Show(obj.Message, "X'eption"); }
}
-
Hi, If you have already linked the PDS dataset to Crystal, don't create a new dataset. Instead, add a new datatable to existing PDS dataset and then add rows to it. After this you can see two tables at Crystal side. Hope this helps, Mika
Thank You Mika, I did it the other way round. After adding the new columns to the dataset. I have updated the dataset schema using .WriteXMLSchema (), this infact, updates the old schema with the one and shows the newsly added column in the fields explorer section of the Crystal Report. Dataset has been updated at its actual location:
PDS.WriteXmlSchema(@"C:VS_Projects\PIN_DataSet.xsd");
And also, I didn't add the new dataset, I have used the old one instead. Thanks again for all the help extended.
-
Thank You Mika, I did it the other way round. After adding the new columns to the dataset. I have updated the dataset schema using .WriteXMLSchema (), this infact, updates the old schema with the one and shows the newsly added column in the fields explorer section of the Crystal Report. Dataset has been updated at its actual location:
PDS.WriteXmlSchema(@"C:VS_Projects\PIN_DataSet.xsd");
And also, I didn't add the new dataset, I have used the old one instead. Thanks again for all the help extended.