是否有可能更快地使用大数据填充datagridview?

时间:2018-02-19 07:43:10

标签: vb.net

这是我的代码。它已经在工作了。但填充datagridview需要很长时间才能完成。

Public Sub Reprint_Pop1(ByVal i As Integer, ByVal grd As DataGridView, ByVal display As Integer, Optional ByVal search As String = Nothing, Optional ByVal a As String = Nothing, Optional ByVal b As String = Nothing)



        Try
                cn.Open()
                Select Case i
                    Case 0
                        sql = "select pos.posno, transdate, transtime, sum(trans.qty) as totalitems, format(sum(trans.amount),2) as amount, printdesc from tblpostrans as trans
    left join tblpos as pos on trans.posno = pos.posno
    where pos.status = 'Completed' group by pos.posno order by transid desc limit 0, @display"
                    Case 1
                        sql = "select pos.posno, transdate, transtime, sum(trans.qty) as totalitems, format(sum(trans.amount),2) as amount, printdesc from tblpostrans as trans
    left join tblpos as pos on trans.posno = pos.posno
    where pos.status = 'Completed' and (transtime like @search or transdate like @search or trans.amount like @search or pos.posno like @search or printdesc like @search) group by pos.posno order by transid desc limit 0, @display"
                    Case 2
                        sql = "select pos.posno, transdate, transtime, sum(trans.qty) as totalitems, format(sum(trans.amount),2) as amount, printdesc from tblpostrans as trans
    left join tblpos as pos on trans.posno = pos.posno
    where pos.status = 'Completed' and str_to_date(transdate, '%Y-%m-%d') between @a and @b and (transtime like @search or transdate like @search or trans.amount like @search or pos.posno like @search or printdesc like @search) group by pos.posno order by transid desc limit 0, @display"
                End Select

                cmd = New MySqlCommand(sql, cn)
                cmd.Parameters.AddWithValue("display", display)
                cmd.Parameters.AddWithValue("search", "%" & search & "%")
                cmd.Parameters.AddWithValue("a", a)
                cmd.Parameters.AddWithValue("b", b)
                dr = cmd.ExecuteReader
                grd.Rows.Clear()
                If dr.HasRows = True Then
                    Dim col(4)
                    While dr.Read
                        col(0) = dr("posno")
                        col(1) = dr("transdate")
                        col(2) = dr("transtime")
                        col(3) = dr("amount")
                        col(4) = dr("totalitems")
                        grd.Rows.Add(col)
                    End While
                End If
            Catch ex As Exception
                MsgErr(ex.Message, "Error Encounter")
            Finally
                cn.Close()
            End Try
        End Sub

有没有办法优化这个?喜欢使用适配器或绑定数据源?如果这样的话。我怎么能把它包含在模块中?

0 个答案:

没有答案