C#異步綁定數(shù)據(jù)實現(xiàn)方法
更新時間:2015年09月04日 16:54:42 作者:我心依舊
這篇文章主要介紹了C#異步綁定數(shù)據(jù)實現(xiàn)方法,實例分析了C#操作數(shù)據(jù)庫及異步綁定的相關(guān)實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#異步綁定數(shù)據(jù)實現(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;
}
}
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法
這篇文章主要介紹了C#使用TensorFlow.NET訓(xùn)練自己的數(shù)據(jù)集的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
詳解三種C#實現(xiàn)數(shù)組反轉(zhuǎn)方式
本篇文章主要介紹了詳解三種C#實現(xiàn)數(shù)組反轉(zhuǎn)方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
2017-04-04 
