RajeshIT

I'm binding a Data Table to my Grid View. User will have the option to select the fields(columns) of the data table while running my web application. Then the grid view reflects these changes.

My problem is generating reports. Crystal reports or Reports in .net not supporting dynamic schema binding. I'm not able to change the columns of my report in run time.

If anybody having knowledge on this please try to solve my problem.

This is the way i'm creating my data table.


string[] myList={"computername","DomainName","ObjectGUID","objectSid",
"objectClass","TrustedforDelegation","ComputerStatus",
"Role","lastLogon","dnsHostname","operatingSystem",
"operatingsystemServicepack","operatingsystemVersion",
"description","distinguishedname","location","ManagedBy",
"memberOf","primaryGroupID","Whencreated","Whenchanged",
"ou","userAccountControl"};

Public Datatable GetMyTable(string[] adAttributes)
{
DataTable myTable = new DataTable();
for (int index = 0; index < adAttributes.Length; index++)
{
myTable.Columns.Add(adAttributes[index], typeof(string));
}
//I'm adding rows accordingly

}

myList changes according to user selected fields.
I need to get report of user selected table.




Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

It is possible to generate dynamic report but it wont be fully dynamic when it comes to formatting.If your field size varies a lot then there will be waistage of space and secondly all fields will appear as string and you will have to apply conversion and formulas.Also change in columns used can causelot of empty space on your report, only way to remove this space is if its possible to move a box position during runtime, if thats possible then you can create fully dynamic report,ill try to find if there is anything like that.
If still want to do it.


Create a typed dataset and create a table , remember use the same table name in your code when you createtable in DataSet in code.

DataTable myTable = new DataTable();


this "myTable" name and typed dataset table name should be same.Now add columns in your typed DataSet
like this
FIELD0 type String
FIELD1 and so on
You have to add as many field as max number of columns possible.

Do not add columns in you untyped DataSet as you are doing in your code, because its boud to change on user selection.

Just add these names FIELD0,FIELD1,....upto same sumber and same type as you put in Typed DataSet.

Now add parameters to your Report same as number of columns added to your DataSet.
Set values of these parameters in same order as Data in your dataSet, like you did in your code above, instead of adding to dataset , add this string values to parameters,
remember again , add these parameters in order in which you enter column data,These parameters are for Header Objects.

for (int index = 0; index < adAttributes.Length; index++)
{
myTable.Columns.Add(adAttributes[index], typeof(string));
}


Once its done, in your CrystalReports go to DataBase Fields>Add/Remove DataBase>More Data Sources>ADO.NET(XML)

now mention path to your Typed DataSet.

Now put those FIELD0,FIELD1,..... on your report and above them in page header place your parameters.

Regarding formatting those fields, upto some level you can control formatting in you code at runtime.
For that explore all formatting options available for a text Object.

dont forget to pass data set to report

DataSet object = new DataSet(**same name as typed dataset);

ReportName objRpt = new ReportName();

objRpt.SetDataSource(object);

crystalReportViewer1.ReportSource = objRpt;





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

Jonathan Wong

What do you mean

" ReportName objRpt = new ReportName(); "

Is the ReportName is the crystalReportname.rpt file





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

Yes its is report name, more appropriate would be , its report file class name,In DOT NET when you add report to your project a class file is created for report .Its the name of class file.Usually its the same as report file name.





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

Smita_M

Hi Rajesh

R u able to generate reports dynamically Can u send me sample code

Thanks

Smita






Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

I have put on a sample, but remember its just a sample and its not fully dynamic as i said, there is problem with formatting fields where field size varies too much.This approach is good for reports where filed size doesnt vary much.

Copy Paste the link :

www.angelfire.com/realm3/runeblade/files/Report.zip





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

Smita_M

Thanks a lot .




Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

laxmisatya

hi,

iam new to .net.

present iam doing crystal Reports in .net 2005 C# using Web App.

Is it Possible to generate reports trough Dataset in .net2005 Web App.

when I add the CrystalReport, iam not get the object to tht.

through DateSet also iam generating Report in Web App.

Whereas I got the Object to my CrystalReport In .net 2005 Windows But Not In >net 2005 WebApp.

my coding:

string str = "select username from table";

MySqlDataAdapter da = new MySqlDataAdapter(str, con);

DataSet1 ds = new DataSet1();

da.Fill(ds, "table");

CrystalDecisions.CrystalReports.Engine.ReportDocument doc=new CrystalDecisions.CrystalReports.Engine.ReportDocument();

doc.Load("Report1.rpt");

CrystalReportViewer1.ReportSource=doc;

and Iam added naspaces also properly.

WHY iam not getting the object to my report1.rpt in WebApp.

Why Iam not getting the Report through Dataset In WebApp.

Plz HelpMe.

plz provide Somecode it's Very helpful to Me.

Thanks.





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

Its because of path not specified properly, windows application accepts direct path but web application doesn't

try this

doc.Load(Server.MapPath("Report1.rpt"))

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=717035&SiteID=1





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

laxmisatya

captJackSparrow wrote:

Its because of path not specified properly, windows application accepts direct path but web application doesn't

try this

doc.Load(Server.MapPath("Report1.rpt"))

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=717035&SiteID=1

Thanks for sending Reply.

Now it's Working.

Thanks alot.

now i have another doubt, When Iam Taking DataSet Iam Entering the Query.

Then wht is the necessary to again entering the query in codebehind C#.

Thanks In advance.





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

If you change your query then you design will need to be altered too, either you use Server Edition of CR XI R2 or you can sheck out the sample below wich can help you make your report somewhat dynamic.

Copy Paste the link :

www.angelfire.com/realm3/runeblade/files/Report.zip






Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

laxmisatya

captJackSparrow wrote:
If you change your query then you design will need to be altered too, either you use Server Edition of CR XI R2 or you can sheck out the sample below wich can help you make your report somewhat dynamic.

Copy Paste the link :

www.angelfire.com/realm3/runeblade/files/Report.zip


thanks for early responses.

Tht link was not opening.

Now i created two dataset tables.DataSet1 & DataSet2.

How to get CrystalReports using two datasets.

provide some code in C# helpful to me.

Thanks In Advance.





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

try to copy paste the link in browser

you need not create two datasets, just create all tables in only one dataset.

Now in crystal reports go to FieldExplorer > Database Fields > Add/Remove database > More Data Sources > ADO.NET (XML) > Now browse to typed dataset that you included in your project. Remember that name of both typed and untyped dataset should be same.

Code is as you are using already.

string str = "select username from table";

MySqlDataAdapter da = new MySqlDataAdapter(str, con);

DataSet1 ds = new DataSet1("Here typed dataset name");

da.Fill(ds, "table");

CrystalDecisions.CrystalReports.Engine.ReportDocument doc=new CrystalDecisions.CrystalReports.Engine.ReportDocument();

doc.Load("Report1.rpt");

CrystalReportViewer1.ReportSource=doc;

Let me know if you face any problem





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

laxmisatya

thanks for replying me.

Now iam created Two Tables In One DateSet.

The Two Tables are Different Tables With Different Queries.

upto now i access only one DataTable at a time by sendinding one query from codebehind C#.

But now How to Access two tables with Two Different queries in codebehind.

Thanks In Advance.





Re: Crystal Reports for Visual Studio how to generate Dynamic reports?

captJackSparrow

When you execute you first query simple use

da.Fill(ds,"Name of first table");

Now add second dummy table to your same dataset

ds.Tables.Add("Name of second table");

Now use the same adapter but change the query, use second query for command object

da.Fill(ds.Tables["Name of second table"]);

*By names here i am refering to names that you assigned to your tables in typed dataset that you added to your project.