Three asynchronous processing methods for ADO. net2.0-function callback Method

Source: Internet
Author: User

The followingCodeEmbeddedSQLStatementBeginexecutereaderExtract the first five pieces of data andCallbackTo this method.No other processing is required. When the asynchronous call ends, the callback function is triggered and the result set is displayed on the screen.

 

<% @ Page Language ="C #"%>

<% @ Import namespace ="System. Data"%>

<% @ Import namespace ="System. Data. sqlclient"%>

<% @ Import namespace ="System. Configuration"%>

<SCRIPT runat ="Server">

Protected void page_load (Object sender, eventargs E)

{

Sqlconnection dbcon;

Sqlcommand command = new sqlcommand ();

Sqlasyncresult asyncresult;

Dbcon = new sqlconnection ();

Command = new sqlcommand ();

Dbcon. connectionstring =

Configurationmanager. connectionstrings ["Dsn_northwind"]. Connectionstring;

// Selecting top 5 records from the orders table

Command. commandtext =

"Select top 5 MERs. companyName, customers. contactname,"+

 
 "Orders. orderid, orders. orderdate,"+

"Orders. requireddate, orders. shippeddate"+

"From orders, customers"+

"Where orders. customerid = customers. customerid"+

"Order by MERs. companyName, customers. contactname";

Command. commandtype = commandtype. text;

Command. Connection = dbcon;

Dbcon. open ();

// Starting the asynchronous Processing

Asyncresult = command. beginexecutereader (New asynccallback (cbmethod ),

Commandbehavior. closeconnection );

}

Public void cbmethod (sqlasyncresult AR)

{

Sqldatareader ordersreader;

// Retrieving result from the asynchronous Process

Ordersreader = ar. endexecutereader (AR );

// Displaying result on the screen

Gvorders. datasource = ordersreader;

Gvorders. databind ();

}

</SCRIPT>

The callback function allows you to process command execution results in other parts of the Code. This feature is very useful when the command execution process is generally longer, but you don't want users to wait until the process call ends.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.