欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

ADO.NET數(shù)據(jù)異步處理的方法有哪些

這篇文章主要介紹“ADO.NET數(shù)據(jù)異步處理的方法有哪些”,在日常操作中,相信很多人在ADO.NET數(shù)據(jù)異步處理的方法有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”ADO.NET數(shù)據(jù)異步處理的方法有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

10年積累的網(wǎng)站制作、成都做網(wǎng)站經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先網(wǎng)站設計后付款的網(wǎng)站建設流程,更有巴青免費網(wǎng)站建設讓你可以放心的選擇與我們合作。

很多開發(fā)語言都支持異步通信,在ADO.NET中支持異步處理的提供程序有System.Data.SqlClient在針對大批量數(shù)據(jù)插入過更新時,使用ADO.NET數(shù)據(jù)異步處理方法可以不用等待多有數(shù)據(jù)更新完畢才能操作或者進行下步處理,改善了用戶體驗SqlCommand對象方法如下:

ADO.NET數(shù)據(jù)異步處理
BeginExecuteNonQueryEndExecuteNonQuery
◆BeginExecuteXmlReaderEndExecuteXmlReader
◆BeginExecuteReaderEndExecuteReader
◆begin前綴的方法傳入?yún)?shù),end前綴的方法返回輸出參數(shù)和返回值
◆begin前綴方法返回的是IAsyncResult用于追蹤一步方法的執(zhí)行狀態(tài)
◆IAsyncResult.AsnycState用戶自定義的狀態(tài)對象
◆IAsyncResult.AsnycWaitHandle呼叫代碼的等待形式,是等其中的一個異步方法完成還是全部完成
◆IAsyncResult.CompletedSynchronously獲取所有異步方法是否同時完成
◆IAsyncResult.Iscompleted是否執(zhí)行完畢,可以根據(jù)此屬性進行下部動作

在連接字符串中加入"async=true"如果所有的命令都是同步的建議在連接字符串中顯施加入,"async=false"如果有一部分命令是異步執(zhí)行,又有一部分是同步同步執(zhí)行,建議分別建立兩個連接對象,如果"async=true"時,也可以執(zhí)行同步命令,但是會損失一些資源

/**/////obtainconnectionstringsfromconfigurationfilesor  ////similarfacility  ////NOTE:theseconnectionstringshavetoinclude"async=true",for  ////example:  ////"server=myserver;database=mydb;integratedsecurity=true;async=true"  //stringconnstrAccouting=GetConnString("accounting");  //stringconnstrHR=GetConnString("humanresources");  /**/////definetwoconnectionobjects,oneforeachdatabase  //using(SqlConnectionconnAcc=newSqlConnection(connstrAccounting))  //using(SqlConnectionconnHumanRes=newSqlConnection(connstrHR))  //{  ////openthefirstconnection  //connAcc.Open();  ////starttheexecutionofthefirstquerycontainedinthe  ////"employee_info"stored-procedure  //SqlCommandcmdAcc=newSqlCommand("employee_info",connAcc);  //cmdAcc.CommandType=CommandType.StoredProcedure;  //cmdAcc.Parameters.AddWithValue("@empl_id",employee_id);  //IAsyncResultarAcc=cmdAcc.BeginExecuteReader();  ////atthispoint,the"employee_info"stored-procisexecutingon  ////theserver,andthisthreadisrunningatthesametime  ////nowopenthesecondconnection  //connHumanRes.Open();  ////starttheexecutionofthesecondstored-procagainst  ////thehuman-resourcesserver  //SqlCommandcmdHumanRes=newSqlCommand("employee_hrinfo",  //connHumanRes);  //cmdHumanRes.Parameters.AddWithValue("@empl_id",employee_id);  //IAsyncResultarHumanRes=cmdHumanRes.BeginExecuteReader();  ////nowbothqueriesarerunningatthesametime  ////atthispoint;moreworkcanbedonefromthisthread,orwe  ////cansimplywaituntilbothcommandsfinish-inourcasewe'll  ////wait  //SqlDataReaderdrAcc=cmdAcc.EndExecuteReader(arAcc);  //SqlDataReaderdrHumanRes=cmdHumanRes.EndExecuteReader(arHumanRes);  ////nowwecanrendertheresults,forexample,bindthereaderstoanASP.NET  ////webcontrol,orscanthereaderanddrawtheinformationina  ////WebFormsform.  //}   stringcustid="ALFKI";  stringorderid="10643";   //NOTE:connectionstringsdenotedby"connstring"havetoinclude  //"async=true",forexample:  stringconnstring="server=(local);database=northwind;integratedsecurity=true;async=true";  //we'llusethreeconnectionsforthis  using(SqlConnectionc1=newSqlConnection(connstring))  using(SqlConnectionc2=newSqlConnection(connstring))  using(SqlConnectionc3=newSqlConnection(connstring))  {  //getcustomerinfo  c1.Open();  SqlCommandcmd1=newSqlCommand(  "SELECTCustomerID,CompanyName,ContactNameFROMCustomersWHERECustomerID=@id",c1);  cmd1.Parameters.Add("@id",SqlDbType.Char,5).Value=custid;  IAsyncResultarCustomer=cmd1.BeginExecuteReader();  //getorders  c2.Open();  SqlCommandcmd2=newSqlCommand("SELECT*FROMOrdersWHERECustomerID=@id",c2);  cmd2.Parameters.Add("@id",SqlDbType.Char,5).Value=custid;  IAsyncResultarOrders=cmd2.BeginExecuteReader();  //getorderdetailifuserpickedanorder  IAsyncResultarDetails=null;  SqlCommandcmd3=null;  if(null!=orderid)  {  c3.Open();  cmd3=newSqlCommand("SELECT*FROM[OrderDetails]WHEREOrderID=@id",c3);  cmd3.Parameters.Add("@id",SqlDbType.Int).Value=int.Parse(orderid);  arDetails=cmd3.BeginExecuteReader();  }  //buildthewaithandlearrayforWaitForMultipleObjects  WaitHandle[]handles=newWaitHandle[null==arDetails?2:3];  handles[0]=arCustomer.AsyncWaitHandle;  handles[1]=arOrders.AsyncWaitHandle;  if(null!=arDetails)  handles[2]=arDetails.AsyncWaitHandle;  //waitforcommandstocompleteandrenderpagecontrolsaswe  //getdataback  SqlDataReaderr;  DataTabledt;  for(intresults=(null==arDetails)?1:0;results<3;results++)  {  //waitforanyhandle,thenprocessresultsastheycome  intindex=WaitHandle.WaitAny(handles,5000,false);//5secs  if(WaitHandle.WaitTimeout==index)  thrownewException("Timeout");  switch(index)  {  case0://customerqueryisready  r=cmd1.EndExecuteReader(arCustomer);  if(!r.Read())  continue;  lblCustomerID.Text=r.GetString(0);  lblCompanyName.Text=r.GetString(1);  lblContact.Text=r.GetString(2);  r.Close();  break;  case1://ordersqueryisready  r=cmd2.EndExecuteReader(arOrders);  dt=newDataTable();  dt.Load(r);  dgOrders.DataSource=dt;//data-bindtotheordersgrid  dgOrders.Refresh();  r.Close();  break;  case2://detailsqueryisready  r=cmd3.EndExecuteReader(arDetails);  dt=newDataTable();  dt.Load(r);  dgDetails.DataSource=dt;//data-bindtothedetailsgrid  dgDetails.Refresh();  r.Close();  break;   }  }  }

到此,關于“ADO.NET數(shù)據(jù)異步處理的方法有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

本文標題:ADO.NET數(shù)據(jù)異步處理的方法有哪些
分享鏈接:http://aaarwkj.com/article2/gopsic.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供用戶體驗、建站公司、關鍵詞優(yōu)化虛擬主機、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設
免费亚洲一级黄色录像| 亚洲精品在线观看午夜福利| 日本岛国大片一区二区在线观看| 国产三级精品电影久久| 成人免费在线国产视频| 黄片免费视频大全在线观看| 中文字幕加勒比东京热| 日韩视频一区二区三区系列| 国产精品中文字幕日韩在线| 日韩一区二区三区成人| 91精品国产自产在线观看| 精品国产乱码一区二区三区四区| 亚洲av乱码一区二区三| 日韩三级视频一区二区 | 亚洲国产精品中文字幕一区久久| 国产高潮精品呻吟久久av| 色噜噜色一区二区三区| 国产国产人免费人成免费人妖| 国产剧情av在线资源| 麻豆一区二区人妻网站| 国产精品三级电影网| 日本丝袜福利在线观看| 国内传媒视频免费观看| 俄罗斯少妇毛茸茸的高潮| 欧洲精品久久久久久| 亚洲综合国产一二三四五区| 在线看日本十八禁网站| 福利一区福利二区视频| 日本色网一区二区三区四区 | 国产成人av网站在线观看| 亚洲欧美日韩午夜在线| 亚洲香蕉视频在线播放| 日本亚洲一区二区在线观看| 日韩中文字幕资源一区| 久久精品国产视频在热| 久久久精品国产亚洲av色哟哟 | 麻豆资源视频在线观看| 欧美精品亚洲精品国产| 国产原创av剧情在线观看| 久久成人激情免费视频| 日操夜操天天操夜夜操|