Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 20th, 2007, 09:55 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default [RESOLVED]Asynchronous Pages and SqlDataAdapter

Hey all,

I just recently read a great article by Jeff Prosise on Asynchronous Programming. I'm developing an external website for our company and using asynchronous pages seems to be the way to go to get efficient use out of my threads, especially as the website will be making some pretty heavy duty database calls. I'm still fairly new to ASP.NET 2.0 and I've run across a problem that I could really use some help with.

Here is the example code the author uses:

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim task As New PageAsyncTask(New BeginEventHandler(AddressOf BeginAsyncOperation), _
            New EndEventHandler(AddressOf EndAsyncOperation), _
            New EndEventHandler(AddressOf TimeoutAsyncOperation), _
            Nothing)
        RegisterAsyncTask(task)
    End Sub

    Function BeginAsyncOperation(ByVal sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
        Dim connect As String = WebConfigurationManager.ConnectionStrings("AsyncPubs").ConnectionString
        _connection = New SqlConnection(connect)
        _connection.Open()
        _command = New SqlCommand("SELECT title_id, title, price FROM titles", _connection)
        Return _command.BeginExecuteReader(cb, state)
    End Function

    Sub EndAsyncOperation(ByVal ar As IAsyncResult)
        _reader = _command.EndExecuteReader(ar)
    End Sub

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)
        Output.DataSource = _reader
        Output.DataBind()
    End Sub


This actually works quite well, except for my purposes, my grid uses pagination. You can't use pagination with an SqlDataReader. I would have to use an SqlDataAdapter and fill a DataSet and then bind the DataSet to the grid. My problem is I'm not sure how I would do this.

It seems to me, the way this works is the SqlDataReader begins the execution in Function BeginAsyncOperation and the result is passed back to it in the Sub EndAsyncOperation. How would I adapt this to use the SqlDataAdapter instead of the SqlDataReader? The key for this to work seems to be in the BeginExecuteReader and EndExecuteReader methods. I'm not sure if there is a match for these methods with SqlDataAdapter.

Thanks,
Tal
  #2 (permalink)  
Old August 22nd, 2007, 02:05 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For anyone interested, the solution to my problem was quite simple. I used a DataTable and then used the Load method to fill it with the results of the Reader. So basically, I just changed

Code:
Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)
    Output.DataSource = _reader
    Output.DataBind()
End Sub
to

Code:
Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As EventArgs)
    _datatable.Load(_reader)
    Output.DataSource = _datatable
    Output.DataBind()
End Sub
Doing it this way gets around the whole problem of the SqlDataReader not supporting pagination.

Tal
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sqldataadapter vgsgowrisankar C# 2005 7 April 23rd, 2008 04:32 PM
SqlDataAdapter DanRoche .NET Framework 1.x 3 August 20th, 2007 04:04 AM
SqlDataAdapter does not have its properties thaopham215 ASP.NET 2.0 Basics 13 December 6th, 2006 05:15 PM
SqlDataAdapter Issue Tom Wing VB.NET 2002/2003 Basics 2 February 6th, 2006 01:43 PM
sqlDataAdapter webguy@rocketmail.com ADO.NET 1 April 8th, 2004 12:28 AM



All times are GMT -4. The time now is 08:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.