如果是vs2005的话,可以用异步操作
在SQL Server数据库上执行异步操作 问题  
有时候我们需要在SQL Server数据库上执行异步操作,即在后台任务中执行该操作,主程序则可以执行其它操作。解决方案 使用SqlCommand类的BeginExecuteNonQuery、BeginExecuteReader或BeginExecuteXmlReader方法开始执行一个后台数据库操作。这些方法都会返回一个System.IAsyncResult对象,我们可以用它来获取操作的状态或使用同步线程等待该操作完成。使用IAsyncResult对象及SqlCommand相应的EndExecuteNonQuery、EndExecuteReader或EndExecuteXmlReader方法来获取操作的结果。注意:只有SqlCommand类支持这里所将的异步操作,与其等价的Oracle、OleDb等Data Provider的Command类没有提供这种功能。原理 通常我们都需要执行同步的数据库操作,即调用代码会一直等待这些操作完成。这是因为我们通常都会用到数据库操作的结果。但有些时候,异步数据库操作也很有用。注意:要对一个SqlConnection连接执行异步操作,需要在其连接字符串中添加如下属性:Asynchronous Processing=true。BeginExecuteNonQuery、BeginExecuteReader以及BeginExecuteXmlReader的参数可以跟其相应的同步操作方法ExecuteNonQuery、ExecuteReader、ExecuteXmlReader相同,同时它们还提供了重载方法接受两个额外的参数以支持异步操作:一个System.AsyncCallBack类型的委托,操作完成后会调用委托指向的方法。如果该委托为null,那就要使用另一种机制来判断异步操作何时完成了; 
一个object对象引用,运行时通过它与异步操作建立联系。异步操作不能访问这个对象,但我们的代码却可以在操作完成时访问它,这样就可以将异步操作与有用的状态信息联系在一起。 
当心: 在异步操作执行过程中,必须确保我们使用的对象不能被不经意地释放掉。尤其要注意SqlConnection和SqlCommand对象。示例代码: 代码中使用的数据库是Northwind,演示了上述技术的基本用法。class Program
{
    public static void CallbackHandler(IAsyncResult result)
    {
        using (SqlCommand cmd = result.AsyncState as SqlCommand)
        {
            using (SqlDataReader reader = cmd.EndExecuteReader(result))
            {
                lock (Console.Out)
                {
                    Console.WriteLine("Price of the The Most Expensive Products:");                    while (reader.Read())
                    {
                        Console.WriteLine("  {0} = {1}", reader["TenMostExpensiveProducts"], reader["UnitPrice"]);
                    }
                }
            }
        }
    }    static void Main(string[] args)
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = @"server=(local);database=Northwind;uid=sa;Asynchronous Processing=true";
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Ten Most Expensive Products";            conn.Open();
            cmd.BeginExecuteReader(CallbackHandler, cmd);            for (int count = 0; count < 10; count++)
            {
                lock (Console.Out)
                {
                    Console.WriteLine("{0} : Continue processing", DateTime.Now.ToString("HH:mm:ss.ffff"));
                }
                Thread.Sleep(400);
            }
        }        Console.WriteLine();
        Console.ReadLine();
    }
}

解决方案 »

  1.   

    ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.VisualStudio.v80.chs/WD_ADONET/html/e7d32c3c-bf78-4bfc-a357-c9e82e4a4b3c.htm
      

  2.   

    谢谢远方。但我现在用的oracle.有没有解决办法?
      

  3.   

    oracle真的没有办法了么?我连gif都动不了啊
      

  4.   

    查询进行时显示百分比?这个根本没法做啊。除非在查询代码里写进度条代码,但我这个只是一个插入操作,写的空间都没有。而且我写在线程里,主线程根本就没有刷新。oracle数据库操作全部把时间占了。你是怎么做的??
      

  5.   

    asp.net oracle 异步处理,sqlclient 提供beginexecutereader 方法,ORACLE下面有没有类似的处理异步的解决方法呢?