0

我需要在表之间移动数据。这两个表在每个字段的数据类型方面是相同的。但是,当我尝试从一个表中获取数据并将其放在另一个表中时,我得到了错误。毫无疑问,这是一种非常复杂的编程方式,但这是我现阶段所知道的唯一方式。对于我获得Value of type 'System.Linq.IQueryable(Of Integer)' cannot be converted to Integer的每个字段或等效字段,具体取决于数据类型。我已经为此苦苦挣扎了 3 天。请帮忙!

    `input string`
    Dim parseRef As String = txtReferenceCode.Text

    `Convert string to integer value`
    Dim findRecord As Integer = Integer.Parse(parseRef)

    `Query the database for the row to be updated.`
    Dim modQuery = _
        (From m In db.Modules
         Join am In db.Amendments_Awaiting_Approvals On m.Module_code Equals am.Module_code
         Where am.Amendments_ID = findRecord _
         Select m)

    Dim newName = (From n In db.Amendments_Awaiting_Approvals
                   Where n.Amendments_ID = findRecord
                   Select n.Module_name_app)

    Dim newStatus = (From n In db.Amendments_Awaiting_Approvals
                  Where n.Amendments_ID = findRecord
                  Select n.Module_status_app)

    Dim newCredits = (From n In db.Amendments_Awaiting_Approvals
                  Where n.Amendments_ID = findRecord
                  Select n.Module_credits_app)

    Dim newCapacity = (From n In db.Amendments_Awaiting_Approvals
                          Where n.Amendments_ID = findRecord
                          Select n.Module_capacity_app)

    Dim newFee = (From n In db.Amendments_Awaiting_Approvals
                  Where n.Amendments_ID = findRecord
                  Select n.Fee_change)

    Dim newDesc = (From n In db.Amendments_Awaiting_Approvals
                  Where n.Amendments_ID = findRecord
                  Select n.Module_Description_app)

    ` Execute the query, and change the column values
     you want to change.  NB all fields on right had side hold the temp data to be input`
    For Each m As [Module] In modQuery
        m.Module_name = newName
        m.Module_status = newStatus
        m.Module_credits = newCredits
        m.Module_capacity = newCapacity
        m.Fee = newFee
        m.Module_Description = newDesc
4

1 回答 1

5

如果您希望每个查询只有一行;

Dim newFee = (From n In db.Amendments_Awaiting_Approvals
              Where n.Amendments_ID = findRecord
              Select n.Fee_change)

默认情况下,这将返回 Fee_change 的“列表”

Dim newFee = (From n In db.Amendments_Awaiting_Approvals
              Where n.Amendments_ID = findRecord
              Select n.Fee_change).FirstOrDefault

添加 .FirstOrDefault 所以它不再是 iqueryable

于 2013-04-15T11:18:19.023 回答