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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 不老仙翁

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

        }