0

我必须在同一个查询中选择另一列,因为在创建单行时我必须在同一行中添加值。

//代码

  'Loop through the transactions
            For Each iTransactionid In (From TransactionFieldLinq In transactionFieldsCollection Select TransactionFieldLinq.TransactionId).Distinct

                'Create a new data row
                DataRow = DataTable.NewRow()

                'Set the data row properties
                DataRow("TransactionId") = iTransactionid

                'Loop through the transaction fields collection
                For Each TransactionField In (From TransactionFieldLinq In transactionFieldsCollection Where TransactionFieldLinq.TransactionId = CInt(DataRow("TransactionId")))

                    'Set the data row properties
                    DataRow(CStr(TransactionField.FieldId)) = TransactionField.FieldValue

                Next

                'Add the data row to the data table
                DataTable.Rows.Add(DataRow)

            Next

transactionFieldCollection有另一个称为格式的属性StartDateDateTime我还必须在同一查询中选择该StartDate列并将其绑定到DataTable类似 TransactionId。

我怎样才能做到这一点?

4

3 回答 3

0

你需要一个匿名类型。

(From TransactionFieldLinq In transactionFieldsCollection 
 Select TransactionFieldLinq.TransactionId, 
 TransactionFieldLinq.StartDate).Distinct
于 2013-05-13T13:35:44.187 回答
0
select new {TransactionFieldLinq.TransactionId, 
 TransactionFieldLinq.StartDate}
于 2013-05-13T13:39:15.567 回答
0

希望这可以帮助。

//代码

'Loop through the transactions
                For Each iTransactionid In (From TransactionFieldLinq In transactionFieldsCollection Select TransactionFieldLinq.TransactionId).Distinct

                    'Create a new data row
                    DataRow = DataTable.NewRow()

                    'Set the data row properties
                    DataRow("TransactionId") = iTransactionid

                    'Loop through the transactions for start date
                    For Each dtStartDate In (From TransactionFieldLinq In transactionFieldsCollection Where TransactionFieldLinq.TransactionId = iTransactionid And TransactionFieldLinq.StartDate <> CDate("12:00:00 AM") Select TransactionFieldLinq.StartDate)

                        'Set the data row properties
                        DataRow("StartDate") = dtStartDate

                    Next
                    'Loop through the transaction fields collection
                    For Each TransactionField In (From TransactionFieldLinq In transactionFieldsCollection Where TransactionFieldLinq.TransactionId = CInt(DataRow("TransactionId")))

                        'Set the data row properties
                        If (TransactionField.FieldId <> 0) Then
                            DataRow(CStr(TransactionField.FieldId)) = TransactionField.FieldValue
                        End If
                    Next

                    'Add the data row to the data table
                    DataTable.Rows.Add(DataRow)

                Next
于 2013-05-15T07:03:43.070 回答