为dataset手动添加自定义列

 涉及到多表查询,而且其中两列中的数据是由数据库表中的几列经过计算所得出来的,而非数据库中原有的列。

 

 public DataSet GetListNotPayment(string strWhere)
        {
            ds = dal.GetListNotPayment(strWhere);//查询出的dataset
            ds.Tables[0].Columns.Add("yifufangkuan", System.Type.GetType("System.String"));//直接为表创建一新列
            ds.Tables[0].Columns.Add("qianfangkuan", System.Type.GetType("System.String"));//直接为表创建一新列
           
            foreach (DataRow dr in ds.Tables[0].Rows)//将新列分别递归添加到对应的行中
            {

                dr["yifufangkuan"] =Convert.ToString(GetPaymount(Convert.ToInt32(dr["fj_id"])));//GetPaymount()为一个自定义方法
                dr["qianfangkuan"] =Convert.ToString((Convert.ToInt32(dr["dd_chengjiaojiage"]) -  GetPaymount(Convert.ToInt32(dr["fj_id"]))).ToString());

            }
            
            //return dal.GetListNotPayment(strWhere);
            return ds;
        }


posted on 2011-07-26 14:57  学中医的程序员  阅读(183)  评论(0编辑  收藏  举报

导航