我正在使用 datagridview 并从 SQL Server 查询中加载它。当行数少于 50 时,它运行顺畅,但超过 50 行后,需要 2 分钟才能加载。Public Sub GetOldEntryInGrid() ...
我正在使用 datagridview 并从 SQL Server 查询中加载它。当行数少于 50 行时,它运行顺畅,但超过 50 行后,需要 2 分钟才能加载。
Public Sub GetOldEntryInGrid()
Try
If text_ReceiptNo.Text = "" Then
text_ReceiptNo.Focus()
Else
Me.Cursor = Cursors.WaitCursor
Conn.Open()
Query = "Select [Item Code][Product Code],[Item Name][Product Name],[Color],[Lot NO],[Quantity],[Rolls],[Units],[Rate],[Amount],[Description],1 as Chk From [Issue Yarn Outhouse Detail] where [Challan No]=@vouid1"
cmd = New SqlCommand(Query, Conn)
cmd.Parameters.AddWithValue("@vouid1", text_ReceiptNo.Text)
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader)
Conn.Close()
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
DGV_PO.Rows(i).Cells("c_ProductCode").Value = dt.Rows(i).Item("Product Code")
DGV_PO.Rows(i).Cells("c_ProductName").Value = dt.Rows(i).Item("Product Name")
DGV_PO.Rows(i).Cells("c_Color").Value = dt.Rows(i).Item("Color")
DGV_PO.Rows(i).Cells("c_LotNo").Value = dt.Rows(i).Item("Lot No")
DGV_PO.Rows(i).Cells("c_Quantity").Value = dt.Rows(i).Item("Quantity")
DGV_PO.Rows(i).Cells("Rolls").Value = dt.Rows(i).Item("Rolls")
DGV_PO.Rows(i).Cells("c_Units").Value = dt.Rows(i).Item("Units")
DGV_PO.Rows(i).Cells("c_Rate").Value = dt.Rows(i).Item("Rate")
DGV_PO.Rows(i).Cells("c_Amount").Value = dt.Rows(i).Item("Amount")
DGV_PO.Rows(i).Cells("c_Description").Value = dt.Rows(i).Item("Description")
DGV_PO.Rows(i).Cells("c_RowCheck").Value = True 'ds2.Tables("table2").Rows(i).Item("Chk")
Next
Me.Cursor = Cursors.Default
End If
Catch ex As SqlException
MsgBox(ex.Message)
Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
Me.Cursor = Cursors.Default
End Try
End Sub