涉及到多表查询,而且其中两列中的数据是由数据库表中的几列经过计算所得出来的,而非数据库中原有的列。
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;
}
本文详细介绍了如何在多表查询中创建并填充自定义计算列,包括使用自定义方法获取数据并将其应用到新列中,以及遍历结果集进行数据填充的过程。

3万+

被折叠的 条评论
为什么被折叠?



