加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

我可以暂时将数据存储在我的C#.Net应用程序中,以减少从SQL Serve

发布时间:2020-12-16 00:12:31 所属栏目:百科 来源:网络整理
导读:我创建了一个C#.net应用程序,它使用SQL Server 2008数据库表中的日期.有没有办法暂时存储数据,以便我的程序不必为同一组信息重复进行服务器调用?我知道如何提取我需要的信息并创建一个临时数据集,但是,只有特定方法或类可以访问它然后消失.在程序结束之前,
我创建了一个C#.net应用程序,它使用SQL Server 2008数据库表中的日期.有没有办法暂时存储数据,以便我的程序不必为同一组信息重复进行服务器调用?我知道如何提取我需要的信息并创建一个临时数据集,但是,只有特定方法或类可以访问它然后消失.在程序结束之前,我需要将结果普遍可用.

这是我到目前为止所做的,我不知道下一步该怎么做:

SqlConnection ReportConnect = new SqlConnection(ConnectionString);
String reportQuery = @"SELECT DISTINCT DATE FROM dbo.myTable ORDER BY DATE DESC";

ReportConnect.Open();

SqlCommand cmd = ReportConnect.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = ReportConnect;
cmd.CommandText = reportQuery.ToString();

SqlDataReader rdr = cmd.ExecuteReader();

while(rdr.Read()) {
   //I can access the results here 
}

//how do I add this data for the life of the program instance to my current
//dataset.  Let's say the dataset is named "activeDataset"

解决方法

您可以创建单个对象,并将数据存储在此对象中.

请注意,您需要考虑的单吨物体还有很多.

看一下

> Implementing the Singleton Pattern
in C#
> Singleton pattern
> Implementing Singleton in C#

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读