惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
月光博客
月光博客
AI
AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CXSECURITY Database RSS Feed - CXSecurity.com
WordPress大学
WordPress大学
GbyAI
GbyAI
L
Lohrmann on Cybersecurity
O
OpenAI News
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
L
LINUX DO - 最新话题
人人都是产品经理
人人都是产品经理
S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
TaoSecurity Blog
TaoSecurity Blog
C
Check Point Blog
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
The Hacker News
The Hacker News
Y
Y Combinator Blog
Latest news
Latest news
SecWiki News
SecWiki News
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cisco Blogs
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题

博客园 - 不老仙翁

招聘信息(沈阳) 冥王星归位 宇宙的最初三分种(转) 也谈谈ORM 要看世界杯了 试用mapxtreme 2005 v6.6中的一个问题 关于软件开发团队的一些思考 程序员需要天真,写在六一 一个足球狂的军规:世界杯女友/老婆准则 这个项目团队能少了谁? 需求中的一例 vs2005中的小bug 继续说需求 vs 2005的中文版终于出来了 大话需求分析中的方法论(4) 在aspnet中使用wwf的第一个实践 大话需求分析中的方法论(3) 大话需求分析中的方法论(2) 大话需求分析中的方法论(1)
DataSet中DataRelation有个小BUG
不老仙翁 · 2007-09-14 · via 博客园 - 不老仙翁

今天发现了一个小问题,不知道大家遇到没有:
在一个类中作了两个类似的方法,
方法1:返回dataset,tables中有两表,一个是统计一个字段的集合,类似select aa ,sum(value) from table1 ,另一个是明细,类似select aa,bb,cc,value from table1.
然后建立一个relation;主从column都是aa,
方法2:与上一个方法相似,统计的表中统计二个字段,类似select aa,bb,sum(value) from table1,明细与上一个方法相同,同样建立一个relation,主从用数组column,当然是aa,bb两个字段。
在界面中用两个datagridview分别显示统计表及relation中的明细表,单独用没什么问题,但当调用其中一个方法,然后马上调用另一方法时,返回的结果就出问题了。在这时,如果多次连续调用一个方法,就有内存溢出了。
大家不妨验正一下。
我在实际程序中有多个方法,只是在这两个类似的方法连续调用中,会出现问题。

        public DataSet itemseach(DateTime da1, DateTime da2)
        {
            DataSet myset = new DataSet();
            SqlConnection mycnn = new SqlConnection(Properties.Settings.Default.HappyHISConnectionString);
            SqlCommand logcmm = new SqlCommand("select itemname as 项目名称 ,sum(itemvalue) as 合计 from 收费记录 where chargetime >= cast('" + da1.ToString() + "' as datetime) and chargetime <=cast('" + da2.ToString() + "' as datetime) group by itemname", mycnn);
            SqlCommand detailcmm = new SqlCommand("select itemname as 项目名称,...... from 收费记录 where chargetime >= cast('" + da1.ToString() + "' as datetime) and chargetime <=cast('" + da2.ToString() + "' as datetime)", mycnn);
            mycnn.Open();

            SqlDataAdapter logadp = new SqlDataAdapter();
            logadp.SelectCommand = logcmm;
            logadp.Fill(myset, "收费项目");

            SqlDataAdapter detailadp = new SqlDataAdapter();
            detailadp.SelectCommand = detailcmm;
            detailadp.Fill(myset, "明细");

            myset.Tables[0].TableName = "收费项目";
            myset.Tables[1].TableName = "明细";
            DataColumn logcol = myset.Tables["收费项目"].Columns["项目名称"];
            DataColumn logdet = myset.Tables["明细"].Columns["项目名称"];
            DataRelation logrela = new DataRelation("收费项目", logcol, logdet, true);
            myset.Relations.Add(logrela);
            mycnn.Close();


            return myset;

        }

        public DataSet docitemseach(DateTime da1, DateTime da2)
        {
            DataSet myset = new DataSet();
            SqlConnection mycnn = new SqlConnection(Properties.Settings.Default.HappyHISConnectionString);
            SqlCommand logcmm = new SqlCommand("select doctor as 医生,itemname as 项目名称 ,sum(itemvalue) as 合计 from 收费记录 where chargetime >= cast('" + da1.ToString() + "' as datetime) and chargetime <=cast('" + da2.ToString() + "' as datetime) group by doctor,itemname order by doctor", mycnn);
            SqlCommand detailcmm = new SqlCommand("select doctor as 医生,itemname as 项目名称,...... from 收费记录 where chargetime >= cast('" + da1.ToString() + "' as datetime) and chargetime <=cast('" + da2.ToString() + "' as datetime)", mycnn);
            mycnn.Open();

            SqlDataAdapter logadp = new SqlDataAdapter();
            logadp.SelectCommand = logcmm;
            logadp.Fill(myset, "收费项目");

            SqlDataAdapter detailadp = new SqlDataAdapter();
            detailadp.SelectCommand = detailcmm;
            detailadp.Fill(myset, "明细");

            myset.Tables[0].TableName = "收费项目";
            myset.Tables[1].TableName = "明细";

            DataColumn[] logcol = new DataColumn[2];
            DataColumn[] logdet = new DataColumn[2];

            logcol[0] = myset.Tables["收费项目"].Columns["医生"];
            logcol[1] = myset.Tables["收费项目"].Columns["项目名称"];
            logdet[0] = myset.Tables["明细"].Columns["医生"];
            logdet[1] = myset.Tables["明细"].Columns["项目名称"];

            DataRelation logrela = new DataRelation("收费项目", logcol, logdet, true);
            myset.Relations.Add(logrela);
            mycnn.Close();


            return myset;

        }