我认为这种方法后面肯定有改进的地方,但是目前位置我不知道 ,希望各位给于指教
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace OperatorDB
{
public class AsyncSelectData
{
/// <summary>
/// 创建异步执行数据查询
/// </summary>
/// <param name="DBConnect">取得链接</param>
/// <param name="asyncDataAdapter">取得配置器</param>
public AsyncSelectData(SqlConnection DBConnect, SqlDataAdapter asyncDataAdapter)
{
sConnect = DBConnect;
sDataAdapter = asyncDataAdapter;
}
private SqlConnection sConnect;
private SqlDataAdapter sDataAdapter;
private DataTable retDataTable;
private void SelectData_()
{
DataTable Dt=new DataTable();
#region 执行
if (sConnect != null)
{
sConnect.Open();
if (sDataAdapter != null)
{
if (Dt != null)
{
try
{
sDataAdapter.Fill(retDataTable);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
#endregion
;
}
public void SelectData(DataTable Dt)
{
retDataTable = Dt ;
System.Threading.Thread t = new System.Threading.Thread(SelectData_);
t.Start();
do
{
System.Threading.Thread.Sleep(0);
System.Windows.Forms.Application.DoEvents();
}
while (t.ThreadState== System.Threading.ThreadState.Running );
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace OperatorDB
{
public class AsyncSelectData
{
/// <summary>
/// 创建异步执行数据查询
/// </summary>
/// <param name="DBConnect">取得链接</param>
/// <param name="asyncDataAdapter">取得配置器</param>
public AsyncSelectData(SqlConnection DBConnect, SqlDataAdapter asyncDataAdapter)
{
sConnect = DBConnect;
sDataAdapter = asyncDataAdapter;
}
private SqlConnection sConnect;
private SqlDataAdapter sDataAdapter;
private DataTable retDataTable;
private void SelectData_()
{
DataTable Dt=new DataTable();
#region 执行
if (sConnect != null)
{
sConnect.Open();
if (sDataAdapter != null)
{
if (Dt != null)
{
try
{
sDataAdapter.Fill(retDataTable);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
#endregion
;
}
public void SelectData(DataTable Dt)
{
retDataTable = Dt ;
System.Threading.Thread t = new System.Threading.Thread(SelectData_);
t.Start();
do
{
System.Threading.Thread.Sleep(0);
System.Windows.Forms.Application.DoEvents();
}
while (t.ThreadState== System.Threading.ThreadState.Running );
}
}
}