“As'Fieldname'”未在数据集中显示

时间:2014-07-03 19:50:04

标签: sql .net database vb.net

只要我在sql语句中不使用'As Total',以下代码就可以正常工作。任何列名都可以。

           'Get the total number of trusses this type
            sql2 = "SELECT max(sequencenumber) as Total from fitapieces fs WHERE fs.projectnumber = " & TempPieceInfo.ProjectNumber & " And fs.buildingtype = '" & TempPieceInfo.BuildingType & "' And " &
                   " fs.buildingnumber = '" & TempPieceInfo.BuildingNumber & "' And fs.buildinglevel = '" & TempPieceInfo.BLevel & "' And fs.batch = '" & TempPieceInfo.Batch & "' and fs.trussname = '" & TempPieceInfo.Trussname & "'"

            myDataset2 = SelectFromDB(sql)

            If Not myDataset2 Is Nothing Then
                If myDataset2.Tables("CurData").Rows.Count > 0 Then

                    TempPieceInfo.TotalNumberofTrussesThisType = myDataset2.Tables("CurData").Rows(0).Item("Total").ToString.Trim
                End If
            End If

当我使用'As Total'时,我得到“Total”不属于'CurData'表的错误。

enter image description here

使用数据集时使用'As'子句有何不同?

1 个答案:

答案 0 :(得分:0)

sql2方法获得参数SelectFromDB时,您的查询包含在变量sql中。这必然导致问题。请在sql2方法中将参数名称更改为SelectFromDB

希望这会有所帮助!!