帮忙
mc520 2008-07-17 11:40:46 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DB;
using System.Threading;
namespace SourceReadDemo
{
class Class1
{
private bool flag;//用于关闭线程
private bool flag1;
private Thread thread1;
private Thread thread;//定义一个线程
//public delegate void MyInvoke(DataSet ds);//定义一个委托
SqlConnection con = new SqlConnection("server=.;database=pubs;uid=sa;pwd=");
DataSet ds = null;//声明全局的dataset
string sql = "";
public DataSet start(string sql)“SourceReadDemo.Class1.start(string):并非所有的代码路径都返回值
{
this.sql = sql;
//启动线程
flag = true;
flag1 = true;
thread = new Thread(new ThreadStart(threadProc));
thread1 = new Thread(new ThreadStart(threa1));
thread.Start();
thread1.Start();
thread.Priority = ThreadPriority.Highest;//将读数据线程优先
}
////线程回调函数
private void threadProc()
{
while (flag)
{
DataBind();
Thread.Sleep(100);
}
}
private void threa1()
{
while (flag1)
{
qu();
Thread.Sleep(1000);
}
}
public DataSet DataBind()
{
DataSet dss = new DataSet();
try
{
if (sql != "")
{
SqlDataAdapter sdat = new SqlDataAdapter(sql, con);
sdat.Fill(dss, "student");
}
{
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
con.Close();
}
return null;
}
public DataSet qu()
{
try
{
ds = ds.Tables["student"];无法将类型“System.Data.DataTable”隐式转换为System.Data.DataSet”
}
catch (Exception x)
{
MessageBox.Show(("等待数秒后请按‘确定’"));
}
}
public DataSet returnDS
{
get
{
return ds;
}
}
}
}