4 Replies - 6164 Views - Last Post: 16 July 2008 - 06:55 AM Rate Topic: -----

#1 reality_strikes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 08

Storing values into a 2-Dimensional Array

Post icon  Posted 15 July 2008 - 09:30 AM

Hello, Here I'm directly passing the crystal reports parameters through the code, and generating the report but for some obvious reason, I want the records to be stored first of all into a 2-dimensional array and from there writing it back onto Crystal reports.

Note : The reason why I'm looking for 2-Dimensional array is that currently upon execution I'm getting a Crystal Report with repeated records and that too upto the no. of maximum records in table.

To be more clear, lets say, that I have an access database with 30,000 records and whn I generate the crystal report I'm expecting all 30,000 records to be displayed row-by-row. But instead of that I'm getting the first record repeated 30,000 times..........NEED HELP........!!!


The actual code before storing it in 2D-array is as given below:


 private void btnReport_Click(object sender, System.EventArgs e)
{	 
		 try
		{		   
				 makeReport(report_file); 
				 for (int recordCount=0; recordCount <= myTable.Rows.Count; recordCount++)					
				{ 
						  SetParamValue("@parameter1", myTable.Rows[recordCount]["CLNT#"].ToString));				
						  SetParamValue("@parameter2", myTable.Rows[recordCount]"CNAME"].ToString));			 
						  SetParamValue("@parameter3", myTable.Rows[recordCount]["CSEX"].ToString));				
						  SetParamValue("@parameter4", myTable.Rows[recordCount]["CSS#"].ToString()); 
						  crystalReportViewer1.ReportSource = ReportDoc;			
				} 
		}
		catch (Exception ex)		 
	   { 
			   MessageBox.Show(ex.Message, "EXCEPTION");		  
	   }
}



 private void SetParamValue (string paramName, string paramValue)
{ 
	   for(int i=0; i<reportdoc.datadefinition.formulafields.count;>  
	   if(ReportDoc.DataDefinition.FormulaFields[i].FormulaName=="{" + paramName +  "}")	  
	   { 	  
				ReportDoc.DataDefinition.FormulaFields[i].Text = "\"" +paramValue +"\"";
	   }
	   crystalReportViewer1.ReportSource = ReportDoc;
}



 private void makeReport(string ReportFile) 
{
	   ReportDoc.Load(ReportFile); // where ReportFile is the path of report (@"c:/reports/..)
} 


Is This A Good Question/Topic? 0
  • +

Replies To: Storing values into a 2-Dimensional Array

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,705
  • Joined: 16-October 07

Re: Storing values into a 2-Dimensional Array

Posted 15 July 2008 - 09:53 AM

I don't have the tools in front of me, so this is from memory, but here goes...

What you want is to use a typed DataSet for your DataSource. First, create and populate a generic DataSet from a DataAdapter fill. Save the data from the dataset into and xml file with the schema. Also, save the schema on its own as an xsd file.

For connection types in the crystal report, choose something like ADO XML and point the report to the xml data dump. Design your report as you like. When comes time to generated the report in code, just give it data that matches the xml file you used. You do this by incorporating that xsd file into your project and using that as your typed dataset, filling it as you like.

Like I said, can't do specifics at the moment, but this should get you started.
Was This Post Helpful? 0
  • +
  • -

#3 reality_strikes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 08

Re: Storing values into a 2-Dimensional Array

Posted 15 July 2008 - 12:24 PM

baavgai...........thnks for the reply.............but i'm not getting clue of what u r saying.................any simplified response to my question.................pls help



View Postbaavgai, on 15 Jul, 2008 - 09:53 AM, said:

I don't have the tools in front of me, so this is from memory, but here goes...

What you want is to use a typed DataSet for your DataSource. First, create and populate a generic DataSet from a DataAdapter fill. Save the data from the dataset into and xml file with the schema. Also, save the schema on its own as an xsd file.

For connection types in the crystal report, choose something like ADO XML and point the report to the xml data dump. Design your report as you like. When comes time to generated the report in code, just give it data that matches the xml file you used. You do this by incorporating that xsd file into your project and using that as your typed dataset, filling it as you like.

Like I said, can't do specifics at the moment, but this should get you started.

Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,705
  • Joined: 16-October 07

Re: Storing values into a 2-Dimensional Array

Posted 15 July 2008 - 01:06 PM

View Postreality_strikes, on 15 Jul, 2008 - 03:24 PM, said:

but i'm not getting clue of what u r saying


Actually, I'm a little confused.

In this code:
for (int recordCount=0; recordCount <= myTable.Rows.Count; recordCount++) {
	SetParamValue("@parameter1", myTable.Rows[recordCount]["CLNT#"].ToString));                
	SetParamValue("@parameter2", myTable.Rows[recordCount]"CNAME"].ToString));            
	SetParamValue("@parameter3", myTable.Rows[recordCount]["CSEX"].ToString));                
	SetParamValue("@parameter4", myTable.Rows[recordCount]["CSS#"].ToString());
	crystalReportViewer1.ReportSource = ReportDoc;
}



It looks like you're a) reading from a DataTable and B) setting parameter values and your report source over and over again.

This would make more sense:
crystalReportViewer1.ReportSource = myTable;



No matter how I look at it, overwriting your crystalReportViewer1.ReportSource like that makes no sense.
Was This Post Helpful? 0
  • +
  • -

#5 reality_strikes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-July 08

Re: Storing values into a 2-Dimensional Array

Posted 16 July 2008 - 06:55 AM

when I set the ReportSource property as myTable, it displays this error message : "Invalid Report Source".

This error is occuring bcoz ReportSource is used for setting the source (path) of the report.

Any idea abt it.





View Postbaavgai, on 15 Jul, 2008 - 01:06 PM, said:

View Postreality_strikes, on 15 Jul, 2008 - 03:24 PM, said:

but i'm not getting clue of what u r saying


Actually, I'm a little confused.

In this code:
for (int recordCount=0; recordCount <= myTable.Rows.Count; recordCount++) {
	SetParamValue("@parameter1", myTable.Rows[recordCount]["CLNT#"].ToString));                
	SetParamValue("@parameter2", myTable.Rows[recordCount]"CNAME"].ToString));            
	SetParamValue("@parameter3", myTable.Rows[recordCount]["CSEX"].ToString));                
	SetParamValue("@parameter4", myTable.Rows[recordCount]["CSS#"].ToString());
	crystalReportViewer1.ReportSource = ReportDoc;
}



It looks like you're a) reading from a DataTable and B) setting parameter values and your report source over and over again.

This would make more sense:
crystalReportViewer1.ReportSource = myTable;



No matter how I look at it, overwriting your crystalReportViewer1.ReportSource like that makes no sense.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1