我不确定标题是否具有误导性,但我不确定如何总结这个标题。
我在SQL DB中有一个表,其中存在如下记录:
我想在gridview中显示此项目的测量值,如下所示:
我考虑过将目标值选择到列表(实际值相同),如下所示:
Dim cdc As New InternalCalibrationDataContext
Dim allTargetvalues = (From i In cdc.int_calibration_records
Where i.calibration_no = Request.QueryString(0) And
i.calibration_date = Request.QueryString(1)
Select i.measure1_target, i.measure2_target, i.measure3_target).ToList()
然后以某种方式加入列表,虽然我不确定如何加入列表,或者即使这是正确的方法?
答案 0 :(得分:1)
好吧,我先说measure1_target
,measure2_target
等几乎总是表明数据库设计不好。这些应该在另一个表中作为与您发布的表的1对多关系的“多”结束。所以回答你的一个问题:不,这不是正确的方法。
当你的表的结构处于当前状态时,你最好的选择可能是这样的:
Dim cdc As New InternalCalibrationDataContext
Dim allTargetValues As New List(Of Whatever)
For Each targetValue In (From i In cdc.int_calibration_records
Where i.calibration_no = Request.QueryString(0) AndAlso
i.calibration_date = Request.QueryString(1)
Select i)
allTargetValues.Add(New Whatever With {.MeasureNumber = 1,
.Target = targetValue.measure1_target,
.Actual = targetValue.measure1_actual })
allTargetValues.Add(New Whatever With {.MeasureNumber = 2,
.Target = targetValue.measure2_target,
.Actual = targetValue.measure2_actual })
allTargetValues.Add(New Whatever With {.MeasureNumber = 3,
.Target = targetValue.measure3_target,
.Actual = targetValue.measure3_actual })
Next
Whatever
类看起来像这样:
Public Class Whatever
Public Property MeasureNumber As Integer
Public Property Target As Integer
Public Property Actual As Integer
End Class