Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2006, 12:10 PM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data management with ADO.NET

p450

I have tried the example, and it doesn't seem to work (tried the C# one, but the VB one appears to be identical)

As printed:

public void CBMethod(SQLAsynchResult ar)
{
SqlDataReader OrdersReader;
OrdersReader = ar.EndExecuteReader(ar);
gvOrders.DataSource = OrdersReader;
gvOrders.DataBind();
}

1 - VS2005 doesn't know "SQLAsynchResult"; is this "IAsyncResult"?
2 - With Option Strict in place, I can't run "OrdersReader = ar.EndExecuteReader(ar);" - it claims that I can't do this implicit conversion...I've tried to sort this out but haven't succeeded.

Anyone know what to do here?

Thanks

Griff



I can't find "SQLAsynchResult"; should it be "IAsyncResult"?

 
Old February 13th, 2006, 12:57 PM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay - kinda answered this on my own, so thought I'd share it for comments (I might not have got this right of course !)

When I call the BeginExecuteReader, I have to use one of the overloaded methods, passing it a command object. I happen to be using a call back method that handles two different asynchronous DB calls, so also have to pass it the GridView name that I need populating. So, the following bit of code starts this process off:

        switch (CallBackMethodName)
        {
            case "CBAccounts":
                ASynchResult = Command.BeginExecuteReader(new AsyncCallback(CBHandler), new object[] { Command, gvAccounts }, CommandBehavior.CloseConnection);
                break;
            case "CBUsers":
                ASynchResult = Command.BeginExecuteReader(new AsyncCallback(CBHandler), new object[] { Command, gvUsers }, CommandBehavior.CloseConnection);
                break;
        }


Next, I have my method that handles the call back result:

    protected void CBHandler(IAsyncResult ar)
    {
        object[] args = (object[])ar.AsyncState;

        SqlCommand command = (SqlCommand)args[0];
        SqlDataReader AccountsReader = command.EndExecuteReader(ar);

        ((GridView)args[1]).DataSource = AccountsReader;
        ((GridView)args[1]).DataBind();
    }


One caveat - this example on p450 (well, my version of it) works when in debug mode, but when compiled it falls over.

The reason is that if the asynchronous data fetch hasn't completed by the time the page is ready to be sent to the browser then horrible things happen. I can get partially populated data-views or I can get a page error if the data simply hasn't returned in time.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Get data from Excel file using ADO.NET lam_lvl ADO.NET 7 February 27th, 2014 05:19 AM
confusing in ADO.NET Entity Data Model,Linq to sql angelboy ADO.NET 5 November 21st, 2008 05:01 PM
data access and management kaliaparijat C# 1 May 30th, 2008 02:55 AM
Key and Data Management System using .Net web ser MitDac147 .NET Web Services 0 April 14th, 2008 09:10 PM
Using ado.net and data binding Brettvan1 VB.NET 2002/2003 Basics 18 February 6th, 2006 01:39 PM





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