C#异步绑定数据实现方法
程序员文章站
2022-07-22 12:59:04
本文实例讲述了c#异步绑定数据实现方法。分享给大家供大家参考。具体如下:
using system;
using system.collections.gene...
本文实例讲述了c#异步绑定数据实现方法。分享给大家供大家参考。具体如下:
using system; using system.collections.generic; using system.text; using system.data.sqlclient; using system.data; using system.windows.forms; namespace windowsapplication2 { public class asynccallbackopeartion { private static datagridview datagridview; public static void asynccallback(string connectionstring, string sql, datagridview dgv) { datagridview = dgv; connectionstring += ";asynchronous processing=true"; sqlconnection conn = new sqlconnection(connectionstring); sqlcommand command = new sqlcommand(sql, conn); conn.open(); command.beginexecutereader(new asynccallback(asynccallback), command); } static void asynccallback(iasyncresult ar) { if (ar.iscompleted) { sqlcommand com = (sqlcommand)ar.asyncstate; sqldatareader dr = com.endexecutereader(ar); datatable dt = new datatable(); dt.load(dr); dr.close(); if (datagridview.invokerequired) { updatedg ur = new updatedg(databin); datagridview.invoke(ur, dt); } } } delegate void updatedg(datatable dt); public static void databin(datatable dt) { datagridview.datasource = dt; } } }
希望本文所述对大家的c#程序设计有所帮助。
推荐阅读