Hi,
I have 2 overloaded methods given below
public DataSet LoadDataSet(string SPNAME,string FieldID)
{
sqlcommand cmd=new sqlcommand;
}
============================================
public DataSet LoadDataSet(string SPNAME,string FieldID,string FieldName)
{
sqlcommand cmd=new sqlcommand;
}
Now instead of creating 2 objects of the same class, can i declare a sqlcommand object and use it in any number of methods.. i want to put this sqlcommand object in a global class and use it.. Is this correct?
Creating many objects of same class...
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


VulpesRank #55 · 29.2K reputationPosted May 8, 2013, 12:16 AM EDT
If you're going to put it in a global class, I'd make it static so that it can be accessed throughout the rest of the application without the need for an object reference.
class Global
{
private static SqlCommand cmd = new SqlCommand();
public static SqlCommand Cmd { get { return cmd; }}
}
You can then access with Global.Cmd.
Suma M161 reputationPosted May 8, 2013, 4:21 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 8, 2013, 11:08 AM EDT
That should then be accessible throughout the application including in the Page_Load eventhandler.