这个你最好在sql中就组织好,要不就别直接挂数据集,遍历数据集,填充到grid,这样可以自己统计合计,增加行列,控制比较简单
解决方案 »
- asp+access的网站模版 可否拿来进行ASP.NET(C#)的2次开发?
- C#中的DateTime结构,是怎么样实现时间的tobinary()的?
- C#问问
- 64位系统下c#和fortran混合编程的问题
- 刷新页面时,如何保留动态生成的RadioButtonList的选择状态
- 【菜鸟提问】在智能设备(PDA)上,我要使用textbox的enter事件,请问该怎么写啊?谢谢
- 在Socket编程中各位都是用什么方法区分消息的边界,急用!~
- vs.net 2005中文版下载地址收藏
- .Net的数据库连接问题
- C# 。net中控件DataGridView的列排序
- C# 开发eDna数据库读取历史数据的问题,大神请进!急
- Microsoft Enterprise Library 有什么用?
string Sql = "select dwmc as 单位名称,count(case when t.zl in 'A' then 'A' end) A类卡,count(case when t.zl in 'B' then 'B' end) B类卡,count(case when t.zl in 'C' then 'C' end) C类卡,count(case when t.zl in 'D' then 'D' end) D类卡,count(case when t.zl in 'E' then 'E' end) E类卡,count(case when t.zl in 'F' then 'F' end) F类卡,count(case when t.zl in 'T' then 'T' end) T类卡 from T_TRUCK t where 1=1"; string KZT_First; //定义将要截取的卡状态首字母为字符串类型
KZT_First = comboBox1.Text.Trim().Substring(0, 1);//截取卡状态文本框的首字母
Sql += "and t.gsbz = '" + KZT_First + "'";//查询选中的卡状态的数据,卡状态为必选项 //查询选中的单位的数据,为非必选项
if (comboBox4.Text != "")
{
if (comboBox3.Text == "")
{
Sql += "and t.dwdm like '" + comboBox4.Text + "%'";
}
if (comboBox3.Text != "")
{
Sql += "and t.dwdm = '" + comboBox4.Text + "'";
} }
if (textBox1.Text != "")
{
if (textBox2.Text == "")
{
Sql += " and To_Char(t.bkq,'yyyy/MM/dd') = '" + textBox1.Text + "'";
}
if (textBox2.Text != "")
{
Sql += " and To_Char(t.bkq,'yyyy/MM/dd') between '" + textBox1.Text + "' and '" + textBox2.Text + "'";
}
}
Sql += "group by dwmc order by dwmc";//数据分组及排序
我觉得已经很复杂了,再如何添加呢?还有您说的第二种遍历数据集如何实现的呢?我刚开始做编程实在不懂,能不能给个代码?谢谢了!
个dt 新加 一列 或 一行 public static System.Data.DataTable ColumnsAdd(Query_Cost_FeeInfo cfi)
{
System.Data.DataTable dt = Cost_FeeInfoManager.GetBillNumberInfo(cfi);
if (dt != null)
{
DataColumn dtColumnTotal = new DataColumn("合计", typeof(decimal));
dt.Columns.Add(dtColumnTotal);
for (int i = 0; i < dt.Rows.Count; i++)
{
decimal money = 0;
//从第九列开始合计,因为前几列都是 字符类型 不需要合计,我这个是 行转列,并且把要合计的列 固定在第九列了
for (int j = 9; j < dt.Columns.Count; j++)
{
if (dt.Columns[j].ColumnName != "合计")
{
if (dt.Rows[i][j] != DBNull.Value)
money += Convert.ToDecimal(dt.Rows[i][j]);
dt.Rows[i]["合计"] = money;
}
}
}
DataRow drNew = dt.NewRow();
dt.Rows.Add(drNew);
for (int i = 9; i < dt.Columns.Count; i++)
{
if (dt.Columns[i].ColumnName == "合计")
{
decimal money = 0;
for (int row = 0; row < dt.Rows.Count; row++)
{
if (dt.Rows[row][i] != DBNull.Value)
{
money += Convert.ToDecimal(dt.Rows[row][i]);
} }
dt.Rows[dt.Rows.Count - 1][i] = money;
}
dt.Rows[dt.Rows.Count - 1]["经营单位"] = "总计";
}
}
return dt;
}