Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I created a asp.net,C# application that uses Add/update/delete from a sql server 2005 database table. Is there a way for me to temporarily store the data so that my program does not have to repeatedly make server calls for the same set of information. I need the results to be universally available until the program closes.
This is what I have so far and I am not sure where to go next:
public DataTable getsanctioneremail(string company, string locno, string Empcode)
        {
            string sConnString = "";
            sConnString = getConnectionStringForPerdb(company);
            SqlConnection conn = new SqlConnection(sConnString);
            SqlDataAdapter dAd = new SqlDataAdapter();
            SqlCommand dCmd = new SqlCommand("LeaveApp_getSanctionEmail", conn);
            conn.Open();
            dAd.SelectCommand = dCmd;
            dAd.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataSet dSet = new DataSet();
            try
            {
                dCmd.Parameters.AddWithValue("@company", company);
                dCmd.Parameters.AddWithValue("@locno", locno);
                dCmd.Parameters.AddWithValue("@Emp_Num", Empcode);
                dAd.Fill(dSet, "tblgetEmpemail");
                return dSet.Tables["tblgetEmpemail"];
            }
            catch
            { 
                throw;
            }
            finally
            {   dSet.Dispose();
                dAd.Dispose();
                //conn.Close();
                conn.Dispose();   }
        }

if possible please send me the code.
thanks
avijit
Posted
Updated 8-Aug-11 1:30am
v2

You have declare globel dataset varible as DataSet type..
And you can access this dataset varible where you want ..
 
Share this answer
 
Just move your DataSet to a class level private variable instead of a local one, and do not Dispose it.
Alternatively, store the DataTable you return from getsanctioneremail in a class level private variable.
 
Share this answer
 
If you use asp.net you can store the data in sessionvariables.
These Sessionvariable automatic destroys by closing the website or running into timeout.

for examlpe you have your data in dSet:
C#
Session["DBData"] = dSet;


Now you have all your Data in a temporary Sessionvariable.
You can read the data like this:

C#
DataSet ds = (DataSet)Session["DBData"];
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900