Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# using CrystalReports

Status
Not open for further replies.

bond24

Programmer
Joined
Jan 9, 2008
Messages
24
Location
US
hi all,

im new to this forum, i need some help

i m dealing with c# and crystal reports
Outline: i have 20+ reports in which i have to generate dynamically depending on user generation.
Depending on the user selects the report, the report options will change,for example if user select report1, then he will get some report options ( like 2 combobox - city and state and one textbox option-Name)
If user select report 2 , then he will get other set of options(like 3 combos-country,county,zip and one textbox-date etc).I wrote individual dynamic sql query for each report,what my problem is i have to write single dynamic sql query method(BuildSql()), so when ever user click either report 1 or report 2 ,it should execute BuildSql(), method and display results.

I hope i make it clear for u guys

Thanks in advance
 
the crudest solution is to build a switch statment. of course this could be refactored into a much more elegant solution, but it should get your started.
Code:
public class SqlStringBuilder
{
public string BuildSqlStatementBasedOn(string nameOfReport)
{
   switch(nameOfReport)
   {
       case "Report1":
           return "select * from foo where bar=@id";
       case "Report2":
           return "select * from bar where foo=@id";
       default:
          throw new MissingReportException("Missing report " + nameOfReport);
   }
}
}

public class MissingReportException : Exception
{
   public MissingReportException(string message)
      : base(message) 
   {
   }
}
now you can use the sql statement in conjunction with a idbcommand object, assign the parameters, fetch the data, populate the report.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
hi Mr.Meckley,

Thanks for giving me a Suggestion.
As i said , i exactly did the same thing by writing individual dynamic sql query for each report by using switch statement.
This what i m doing
case:report1
{
report1()
}
case:report2()
{
report2()
}
private void report1()
{
sqlConnection mycon = new sqlConnection();
//i gave my database and server information
string select = null;
select = "select * from view where '+BuildString1()+'"
// the above line i m building where clause dynamically depending on the user selected options
SqlDataAdapter myDA = new sqlDataAdapter(select,mycon)
Dataset ds = new Dataset();
myDA.Fill(ds,"view");
// code still there

}

private string BuildString1()
{
string sqlselect="(1-1)";

// so here i am getting values from the first page by using sessions.
// Here i am making dynamic where clause by checking each every field whether it is null or not
if(city!=String.Empty)
{
sqlselect = sqlselect + "(tbl_City ='"+resultCity+"')";
// tbl_City - database field
// resultCity- value got from session variable

}
//Above is the example how i make where clause dynmaically


// After making where clause dynamically i m sending back to select statement
}

similary i created for report2 and BuildQuerystring2 again.

what my problem is instead of dynamically creating BuildQuerystring1,BuildQuerystring2,BuildQuerystring etc.I want to create one BuildQueryString which will be used for all reports.
Even if it is report 1 or report 2
it will go to only one BuildQueryString and get information selected by user in first page.

For me its working indivdually, but i m not getting the one which i talked above.

I hope u got an idea what i am talking to!

can you help!

Thank you
Ravi Surapaneni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top