Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cjhardie
Yak Posting Veteran
58 Posts |
Posted - 2007-05-08 : 15:14:43
|
Alright I have a bunch of classes that are for excel reports. I want to make one class that will work for all these reports. They all have the same code except for a few spots where it is the stored procedure name or the public class name.Any ideas? |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-05-08 : 15:36:00
|
You haven't really given us any specific information that we can use to help you. Re-read your question from a neutral perspective and ask yourself: "Can I really expect that people will be able to understand my situation based on the information I've provided?"- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
cjhardie
Yak Posting Veteran
58 Posts |
Posted - 2007-05-08 : 15:52:01
|
Here is the class. There are about 25 different classes that look just like this except for the things in blue. I would like to make one and have the things in blue be some type of variable or something.using System;using System.Data;using AdTrack.classes;using System.Data.SqlClient;namespace AdTrack.classes{ /// <summary> /// Summary description for ExcelReportFranchiseStatementMarketing. /// </summary> public class ExcelReportFranchiseStatementMarketing: ExcelReport { public ExcelReportFranchiseStatementMarketing() { } public ExcelReportFranchiseStatementMarketing( System.Collections.Specialized.NameValueCollection theCollection, Report theReport ) : base( theCollection, theReport ) { } public override DataSet run() { parameters = new SqlParameter[theReport.ReportParmsList.Count]; int i = 0; foreach( Report r in theReport.ReportParmsList ) { if( r.ParmDataType == "Int" ) { parameters[i] = new SqlParameter( "@" + r.ParmName, SqlDbType.Int ); if( theCollection["Parm" + r.ParmID.ToString()] != null ) { parameters[i].Value = theCollection["Parm" + r.ParmID.ToString()]; } } else if( r.ParmDataType == "Date" ) { parameters[i] = new SqlParameter( "@" + r.ParmName, SqlDbType.DateTime ); if( theCollection["Parm" + r.ParmID.ToString()] != null ) { parameters[i].Value = theCollection["Parm" + r.ParmID.ToString()]; } } i++; } DataSet theSet = DataAccess.ExecuteDataSet( this._connectString, CommandType.StoredProcedure, "rptFranchiseStatement_Marketing", parameters ); //theSet.Tables[0].Rows[0].Delete(); return( theSet ); |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-05-08 : 16:08:52
|
You only need one class; what should change is that when you create a new instance of the class, you pass in an argument that indicates which stored procedure to call. You already have a constructor that accepts "theCollection" and "theReport", just add a constructor which accepts "theStoredProcedure" as well (a simple string) and then use that in in place of the string literal.Sounds like you might need to do some reading on object oriented programming and the concept of classes versus objects; I know, I know, you don't have time and all that (no one ever does ) but it will be really helpful to get some education on OOP concepts since without those basics you really will end up over complicating things and making things harder on yourself than necessary. This is a great example that illustrates the difference between the two and what happens when you confuse them.By the way -- why does every variable have "the" in front of it!? Very annoying! - Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
cjhardie
Yak Posting Veteran
58 Posts |
Posted - 2007-05-08 : 16:49:31
|
Thanks a lot that helped. |
|
|
|
|
|
|
|