开发者

stop until code ran

开发者 https://www.devze.com 2023-03-05 09:22 出处:网络
So im pulling data from a db and then count开发者_Go百科ing all the data on that db but itcounts before the data is pulled. Anyway to stop this?

So im pulling data from a db and then count开发者_Go百科ing all the data on that db but it counts before the data is pulled. Anyway to stop this?

    test.SelectCommand = Ssql
    test.SelectParameters.Clear()
    test.DataBind()

    System.Threading.Thread.Sleep(1000)
    counter = OSG.Items.Count

    MsgBox(counter)

cheers!


Count the data source not the items in the datagrid. The datagrid binding will happen asynchronously and will not be accurate. For example if your data source is a datatable then you can:

Dim x As DataTable = New DataTable
Dim counter As Integer
counter = x.Rows.Count

EDIT: To count rows in a SQL data source you have to handle the 'selected' event. Make a class level variable called myRowCount, set it in the selected event and use it after the bind statement:

Dim myRowCount As Integer
Protected SubSqlDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Selected
     MsgBox(e.AffectedRows())
     myRowCount = e.AffectedRows()
End Sub

Then you can use myRowCount elsewhere in the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号