'System.Linq.IQueryable(Of Integer)'无法转换为Integer

时间:2013-04-15 11:14:20

标签: vb.net linq integer type-conversion

我需要在表之间移动数据。这两个表在每个字段的数据类型方面是相同的。但是,当我尝试从一个表中获取数据并将其放在另一个表中时,我会收到错误。毫无疑问,这是一种非常复杂的编程方式,但这是我在这个阶段所知道的唯一方式。对于每个字段,我得到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

1 个答案:

答案 0 :(得分: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以便它不再是一个可以讨论的