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

推荐订阅源

D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
Scott Helme
Scott Helme
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
C
Cyber Attacks, Cyber Crime and Cyber Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
I
Intezer
Spread Privacy
Spread Privacy
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
V2EX - 技术
V2EX - 技术
Google Online Security Blog
Google Online Security Blog
L
Lohrmann on Cybersecurity
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LINUX DO - 热门话题
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Latest news
Latest news
B
Blog
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
L
LangChain Blog
GbyAI
GbyAI
Last Week in AI
Last Week in AI
S
Security Affairs
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
Security Latest
Security Latest
Vercel News
Vercel News
Y
Y Combinator Blog
G
GRAHAM CLULEY
S
Securelist
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
雷峰网
雷峰网

博客园 - 不老仙翁

招聘信息(沈阳) 冥王星归位 宇宙的最初三分种(转) 也谈谈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;

        }