Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Creating Reports using DataSet

Creating Reports using DataSet

Scheduled Pinned Locked Moved Database
csharpcssdatabasehelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reality Strikes
    wrote on last edited by
    #1

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

    }

    W 1 Reply Last reply
    0
    • R Reality Strikes

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

      }

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • W Wendelius

        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

        V Offline
        V Offline
        Verghese
        wrote on last edited by
        #3

        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.

        W 1 Reply Last reply
        0
        • V Verghese

          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.

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome :) Mika

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups