【发布时间】:2020-10-07 00:34:48
【问题描述】:
我正在获取 40k 多条记录的记录集。要求是在表中突出显示我们数据库中存在或不存在的记录。
所以我们所做的是挑选每条记录并使用过程与数据库表进行比较。
If exists(Select FunctionalLocation from EngineeringData where
FunctionalLocation = @Asset_Number
)
Begin
Select 1
End
Else
Begin
Select 0
End
END
但这需要很长时间,有时会超时。
有什么办法可以优化这段代码吗?
For k = 0 To gv_InfoFunctionalLocation.Rows.Count - 1
If k < 50000 Then ' to test only
Dim row = gv_InfoFunctionalLocation.Rows(k)
Dim RowEffect As Integer
Dim dSetReturn As New DataSet
ParamValue(0) = row.Cells(1).Text
ParamValue(1) = row.Cells(4).Text
dSetReturn = Func.SP_ReturnDataset(con, "[dbo].[USP_Check_FunctionalLocations]", True, ParamName, ParamType, ParamValue)
RowEffect = dSetReturn.Tables(0).Rows(0).Item(0)
Dim gRow As GridViewRow = gv_InfoFunctionalLocation.Rows(k)
Dim cBox As CheckBox = CType(gRow.FindControl("chkSelect"), CheckBox)
If RowEffect = 0 Then
'dtFL.Rows(k).Cells("Status").Value = True
'dtFL.Rows(k).ReadOnly = True
gv_InfoFunctionalLocation.Rows(k).BackColor = System.Drawing.Color.Tomato
cBox.Checked = True
Else
gv_InfoFunctionalLocation.Rows(k).BackColor = System.Drawing.Color.YellowGreen
cBox.Checked = False
End If
If cBox.Checked = True Then
btnImportFL.Enabled = True
btnImportFL.BackColor = Drawing.Color.Navy
End If
End If
Next
由于时间和资源不足,是否有快速解决方案?
【问题讨论】:
-
我通过将我想要的列表转换为 XML 字符串并作为单个字符串传递,或者如果单个字符串太长,则作为多个字符串传递。然后加入sql。
标签: sql vb.net for-loop gridview dataset