DataSet中DataRelation有个小BUG

今天发现了一个小问题,不知道大家遇到没有:
在一个类中作了两个类似的方法,
方法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;

        }

posted @ 2007-09-14 16:20 不老仙翁 阅读(...) 评论(...) 编辑 收藏