Gav*_*vin 0 linq vb.net 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
Run Code Online (Sandbox Code Playgroud)
如果您希望每个查询只有一行;
Dim newFee = (From n In db.Amendments_Awaiting_Approvals
Where n.Amendments_ID = findRecord
Select n.Fee_change)
Run Code Online (Sandbox Code Playgroud)
默认情况下,这将返回Fee_change的"列表"
Dim newFee = (From n In db.Amendments_Awaiting_Approvals
Where n.Amendments_ID = findRecord
Select n.Fee_change).FirstOrDefault
Run Code Online (Sandbox Code Playgroud)
添加.FirstOrDefault以便它不再是iqueryable了
| 归档时间: |
|
| 查看次数: |
1771 次 |
| 最近记录: |