跪求高手指点,c#中对sql数据库表内容的操作 可以用DataColumn.Expression 来实现前几个数据的和或公式的运算 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不太懂你的意思,你把数据和公式取出再运算不行,为什么非要用SQL来实现? 示例代码:DataColumn cPrice;DataColumn cTax;DataColumn cTotal;DataTable myTable = new DataTable();//Create the first column.cPrice = new DataColumn();cPrice.DataType = Type.GetType("System.Decimal");cPrice.ColumnName = "price";cPrice.DefaultValue = 50;//Create the second,calculated, column.cTax = new DataColumn();cTax.DataType = Type.GetType("System.Decimal");cTax.ColumnName = "Tax";cTax.Expression = "price*0.2";//Create the third columncTotal = new DataColumn();cTotal.DataType = Type.GetType("System.Decimal");cTotal.Expression = "price + tax ";myTable.Columns.Add(cPrice);myTable.Columns.Add(cTax);myTable.Columns.Add(cTotal); 你要在dataTable中加几个dataColumn,设置dataColumn的Expression比如有表中已经有这样两列unitPrice和quantity,你想求总价,那新加入dataColumn的Expression就可以设置为"unitPrice * quantity" 显示数据之前提出需要计算的数据在C#里面计算,计算后再添加到datagrid中去也可以,这种方法比较好理解了,^_^ 用DataColumn.Expression==XXX但是一般我都是计算好后才写入表格 你在生成dataset的时候手动增加也可以,在调用时通过数据库的查询来计算,直接绑定就行了! 你修改SqlDataAdapter的selectcommand的SQL查询语句呢? 你可以让SQLServer完成你的数据统计啊,效率要高很多!如:select sum(money) 'SUM Money' from orders WinForm C# Excel对比 线程次序问题 初学者问题 问个sql语句 C#如何将多个图标添加到EXE或DLL文件?就象Windows的shell32.dll包括有200多个图标资源。 如何用C#实现粘贴链连 高手帮忙超难问题,急!分数不够再加!!! 50分请高手指教关于socket问题 关于comboBox方面的问题,急... 主扳、CPU、硬盘、光驱升级,求助!!!!!!!!!!!!!!!!!!各位帮忙!!!! ★★★★★关于C#中打印预览的问题?超难解决,请对打印相当了解的高手进来. 才学c# 简单问题也不会,在线等
DataColumn cPrice;
DataColumn cTax;
DataColumn cTotal;
DataTable myTable = new DataTable();//Create the first column.
cPrice = new DataColumn();
cPrice.DataType = Type.GetType("System.Decimal");
cPrice.ColumnName = "price";
cPrice.DefaultValue = 50;//Create the second,calculated, column.
cTax = new DataColumn();
cTax.DataType = Type.GetType("System.Decimal");
cTax.ColumnName = "Tax";
cTax.Expression = "price*0.2";//Create the third column
cTotal = new DataColumn();
cTotal.DataType = Type.GetType("System.Decimal");
cTotal.Expression = "price + tax ";myTable.Columns.Add(cPrice);
myTable.Columns.Add(cTax);
myTable.Columns.Add(cTotal);
比如有表中已经有这样两列unitPrice和quantity,你想求总价,那新加入dataColumn的Expression就可以设置为"unitPrice * quantity"
但是一般我都是计算好后才写入表格
select sum(money) 'SUM Money' from orders