日期:2014-05-20 浏览次数:20762 次
CREATE TRIGGER myTrigger ON myTable FOR UPDATE, INSERT AS UPDATE myTable SET t.E = t.A * t.B FROM test t, inserted i WHERE t.id=i.id
------解决方案--------------------
2L的方法不错:
DataTable _Table = new DataTable();
_Table.Columns.Add("A");
_Table.Columns.Add("B");
for (int i = 0; i != 100; i++)
{
_Table.Rows.Add(new object[] { i, i + 1 });
}
添加计算列
_Table.Columns.Add("Sum(A*B)");
string _Expression = "convert(A,'System.Decimal')*convert(B,'System.Decimal')";
_Table.Columns["Sum(A*B)"].Expression = _Expression;
dataGridView1.DataSource=_Table;
------解决方案--------------------
我写了一个例子:
//给dataGridView绑数据,我在这里动态的加了一些数据。
//A4输入公式,A3用公式计算。
private void button1_Click(object sender, EventArgs e)
{
DataSet t = new DataSet();
System.Data.DataTable tab = new DataTable();
DataColumn d = new DataColumn("A");
DataColumn d1 = new DataColumn("A2");
DataColumn d2 = new DataColumn("A3");
DataColumn d3 = new DataColumn("A4");
DataRow r = tab.NewRow();
tab.Columns.Add(d);
tab.Columns.Add(d1);
tab.Columns.Add(d2);
tab.Columns.Add(d3);
r[0] = "100";
r[1] = "33";
tab.Rows.Add(r);
DataRow r1 = tab.NewRow();
r1[0] = "200";
r1[1] = "333";
DataRow r2 = tab.NewRow();
r2[0] = "300";
r2[1] = "3433";
tab.Rows.Add(r2);
t.Tables.Add(tab);
this.dataGridView1.DataSource = t;
this.dataGridView1.DataMember = t.Tables[0].TableName;