请教高手关于出现某列不属于表的现象
我的存储过程中动态创建的SQL语句查询出一个表,这个表中有一个列名为空,但是有数据都是0填充到datatable表中后,想加一个合计行,每行循环加时出现‘“”列不属于表’
就是列名为空的列不属于表。
经过考虑,我在填充后设置空名的列名,添加了一个列名,结果是这个列后面的列又不属于表了。
不解1
请高手赐教
Public Class Form1 Dim dt As System.Data.DataTable = New System.Data.DataTable Function CreateDataSource() As ICollection Dim dr As System.Data.DataRow dt.Columns.Add(New System.Data.DataColumn("学生班级", GetType(System.String))) dt.Columns.Add(New System.Data.DataColumn("学生姓名", GetType(System.String))) dt.Columns.Add(New System.Data.DataColumn("语文", GetType(System.Decimal))) dt.Columns.Add(New System.Data.DataColumn("数学", GetType(System.Decimal))) dt.Columns.Add(New System.Data.DataColumn("英语", GetType(System.Decimal))) dt.Columns.Add(New System.Data.DataColumn("计算机", GetType(System.Decimal))) Dim i As Integer = 0 While i < 5 Dim rd As System.Random = New System.Random(Environment.TickCount * i) dr = dt.NewRow dr(0) = "BCCN论坛" + i.ToString dr(1) = "不说也罢" + i.ToString dr(2) = System.Math.Round(rd.NextDouble * 100, 2) dr(3) = System.Math.Round(rd.NextDouble * 100, 2) dr(4) = System.Math.Round(rd.NextDouble * 100, 2) dr(5) = System.Math.Round(rd.NextDouble * 100, 2) dt.Rows.Add(dr) System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) End While Dim dv As System.Data.DataView = New System.Data.DataView(dt) Total() Return dv dt.Dispose() End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load DataGridView1.DataSource = CreateDataSource() DataGridView1.AllowUserToAddRows = False End Sub Private Sub Total() Dim dtRow As DataRow = dt.NewRow Dim inttotal(4) As ArrayList For i = 2 To 5 dtRow(i) = CDbl(("SUM(" & dt.Columns(i).ColumnName & ")", "1=1")) Next dt.Rows.Add(dtRow) End Sub End Class