Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 118,861 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,691 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Storing values into a 2-Dimensional Array

 
Reply to this topicStart new topic

Storing values into a 2-Dimensional Array

reality_strikes
post 15 Jul, 2008 - 09:30 AM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 3

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:


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



CODE
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;
}



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

User is offlineProfile CardPM

Go to the top of the page


baavgai
post 15 Jul, 2008 - 09:53 AM
Post #2


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,789



Thanked 73 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

reality_strikes
post 15 Jul, 2008 - 12:24 PM
Post #3


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 3

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



QUOTE(baavgai @ 15 Jul, 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.

User is offlineProfile CardPM

Go to the top of the page

baavgai
post 15 Jul, 2008 - 01:06 PM
Post #4


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,789



Thanked 73 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


QUOTE(reality_strikes @ 15 Jul, 2008 - 03:24 PM) *

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


Actually, I'm a little confused.

In this code:
csharp

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 cool.gif setting parameter values and your report source over and over again.

This would make more sense:
csharp

crystalReportViewer1.ReportSource = myTable;


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

Go to the top of the page

reality_strikes
post 16 Jul, 2008 - 06:55 AM
Post #5


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 3

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.





QUOTE(baavgai @ 15 Jul, 2008 - 01:06 PM) *

QUOTE(reality_strikes @ 15 Jul, 2008 - 03:24 PM) *

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


Actually, I'm a little confused.

In this code:
csharp

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 cool.gif setting parameter values and your report source over and over again.

This would make more sense:
csharp

crystalReportViewer1.ReportSource = myTable;


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

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 01:47AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month