C#異步綁定數(shù)據(jù)實(shí)現(xiàn)方法
更新時(shí)間:2015年09月04日 16:54:42 作者:我心依舊
這篇文章主要介紹了C#異步綁定數(shù)據(jù)實(shí)現(xiàn)方法,實(shí)例分析了C#操作數(shù)據(jù)庫(kù)及異步綁定的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#異步綁定數(shù)據(jù)實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:
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;
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
相關(guān)文章
C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法
這篇文章主要介紹了C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
Unity實(shí)現(xiàn)大轉(zhuǎn)盤的簡(jiǎn)單筆記
這篇文章主要為大家分享了Unity實(shí)現(xiàn)大轉(zhuǎn)盤的簡(jiǎn)單筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2019-02-02
詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式
本篇文章主要介紹了詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
2017-04-04
C#實(shí)現(xiàn)學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2022-08-08
C#使用FileStream復(fù)制一個(gè)任意文件
這篇文章主要為大家詳細(xì)介紹了C#使用FileStream復(fù)制一個(gè)任意文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2019-05-05 
