Hi There
I am doing a project in C# that has a main class that deals with all my SQL methods for my database. I Then have .aspx pages which contain my datagrids etc and I have my .aspx.cs files that I use to access the class and bind my controls. In my class I am accessing database connections and creating commands quite a lot so I have declared these variables in my class like so:
This way I do not have to declare the same variables in every method I create that does something with a database, which makes the code more efficient and saves me typing etc..
The trouble I am having is in my aspx.cs file. I have a number of methods that access the data access methods in my class, with that a number of them pass the same session variable to the class, and for some reason I can't put them at the top like in my class, so I end up with the following:
So if I was to create another method that uses the same variable, I would have to re-declare it in effect. It works like this but I must be doing something wrong as its not the most slimline code out there. The question is am i missing out anything glaringly obvious?
Thanks
I am doing a project in C# that has a main class that deals with all my SQL methods for my database. I Then have .aspx pages which contain my datagrids etc and I have my .aspx.cs files that I use to access the class and bind my controls. In my class I am accessing database connections and creating commands quite a lot so I have declared these variables in my class like so:
Code:
public class ABGManagement
{
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\\Databases\\Support.mdb";
System.Data.OleDb.OleDbCommand ObjCmd = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbDataAdapter DataAdapter = new System.Data.OleDb.OleDbDataAdapter();
System.Data.DataSet dataSet = new System.Data.DataSet();
This way I do not have to declare the same variables in every method I create that does something with a database, which makes the code more efficient and saves me typing etc..
The trouble I am having is in my aspx.cs file. I have a number of methods that access the data access methods in my class, with that a number of them pass the same session variable to the class, and for some reason I can't put them at the top like in my class, so I end up with the following:
Code:
protected void GetMaintenance()
{
string SessionWorkstationID = "" + Session["SessionWorkstationID"];
ABGManagement TheManagement = new ABGManagement();
Maintain.DataSource = TheManagement.GetWorkstationJobs(SessionWorkstationID);
Maintain.DataBind();
}
So if I was to create another method that uses the same variable, I would have to re-declare it in effect. It works like this but I must be doing something wrong as its not the most slimline code out there. The question is am i missing out anything glaringly obvious?
Thanks