将数据临时存储到数据集中... [英] temporary store data into the dataset...
问题描述
亲爱的所有人,
我创建了一个asp.net,C#应用程序,该应用程序使用sql server 2005数据库表中的Add/update/delete.有没有一种方法可以让我临时存储数据,以便我的程序不必重复对同一组信息进行服务器调用.在程序关闭之前,我需要通用的结果.
这是我到目前为止的内容,我不确定下一步要去哪里:
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(); }
}
如果可能的话,请给我发代码.
谢谢
avijit
if possible please send me the code.
thanks
avijit
推荐答案
您已将Globel数据集声明为DataSet类型. 而且,您可以在所需的位置访问此数据集变量..
You have declare globel dataset varible as DataSet type..
And you can access this dataset varible where you want ..
只需将DataSet移到类级别的私有变量而不是局部变量,而不必Dispose
it.
或者,将从getsanctioneremail
返回的数据表存储在类级别的私有变量中.
Just move your DataSet to a class level private variable instead of a local one, and do notDispose
it.
Alternatively, store the DataTable you return fromgetsanctioneremail
in a class level private variable.
如果使用asp.net,则可以将数据存储在sessionvariables中. 这些Sessionvariable会通过关闭网站或进入超时状态而自动销毁.
例如,您将数据存储在dSet中:
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:
Session["DBData"] = dSet;
现在,您将所有数据都保存在一个临时的Sessionvariable中.
您可以像这样读取数据:
Now you have all your Data in a temporary Sessionvariable.
You can read the data like this:
DataSet ds = (DataSet)Session["DBData"];
这篇关于将数据临时存储到数据集中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!