如何通过两个数据集线程填充GridView? [英] How to Fill a GridView by Threading with two datasets?

查看:54
本文介绍了如何通过两个数据集线程填充GridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的场景:

我将从两个存储过程中获取一些数据集。我将第一个存储过程数据存储到datasetA中。第二个存储过程的数据将存储在datasetB中。我有另一个常见的数据集C。在那个DatasetC上,我将合并这两个数据集。



合并数据集后我必须在Gridview中显示。



现在我的问题是,

我必须使用threadstart(线程)同时运行这两个存储过程。

第一个存储过程的时间延迟为8秒,第二个SP的时间延迟为3秒,



我需要填写网格视图,当第二个完成后它必须等待第一个存储过程,After First Sp完成它需要合并第二个,它必须在网格视图中显示。



请帮助我清楚这一点。



对于您的种类参考:

第一个存储过程

Hi to Everyone,

My Scenario:
I will get some set of datas from two stored procedure. I will store first stored procedures data into datasetA. And data of second Stored procedure will be stored in datasetB. i have an another common datasetC. On that DatasetC i am going to merge these two datasets.

After Merging the Datasets i have to show in Gridview.

Now my Problem is,
I have to run those two stored procedures at a same time using threadstart(threading).
First Stored Procedure has a time delay of 8sec, and second SP has a time delay of 3 sec,

I need to fill the grid view when the second one got finished and it has to wait for the first stored procedure, After First Sp got finished it needs to merge with second one and it have to shown in grid view.

please help me to get clear out of this.

For your Kind Reference:
First Stored Procedure

Create procedure Athread
as
begin
WAITFOR DELAY '00:00:08'
select * from area where areaname LIKE 'C%';
end





第二个存储过程



Second Stored Procedure

Create procedure Bthread
as
begin
WAITFOR DELAY '00:00:03'
select * from area where areaname LIKE 'F%';
end







我在按钮事件中调用以下代码




I am Calling the below code in an Button Event

Thread thread1 = new Thread(new ThreadStart(Athread));
            Thread thread2 = new Thread(new ThreadStart(Bthread));

            thread1.Start();
            thread2.Start();





我有两个函数来调用这些Sp并在Grid视图中显示两个



I am Having two Functions to call these Sp and two display in Grid view

dataset dsA;
dataset dsB;
dataset dsCommon;
public void Athread()
        {
            dsA = ExecSP("Athread");
            if (dsA.Tables[0].Rows.Count > 0)
            {
                dsCommon.Merge(dsA);
                gvthread.DataSource = dsCommon;
                gvthread.DataBind();            
            }
            return;
        }
        public void Bthread()
        {
            dsB = ExecSP("Bthread");
            if (dsB.Tables[0].Rows.Count > 0)
            {
                dsCommon.Merge(dsB);
                gvthread.DataSource = dsCommon;
                gvthread.DataBind();     
            }
            return;

        }





请帮助我完成线程并完成此操作...



Please help me in Threading and to finish this...

推荐答案

Hello Maria,



如果不使用线程,您可以调用您的方法:

Hello Maria,

Without using thread you can call your method like:
Page_Load(....)
{
    if(!IsPostBack)
    {
         functionA();
    }
}
public void functionA()
{
      dsA = ExecSP("Athread");
      if (dsA.Tables[0].Rows.Count > 0)
      {
           dsCommon.Merge(dsA);
           gvthread.DataSource = dsCommon;
           gvthread.DataBind();
           //From here you can call your functionB
           functionB();
      }
return;
}
public void functionB()
{
      dsB = ExecSP("Bthread");
      if (dsB.Tables[0].Rows.Count > 0)
      {
           dsCommon.Merge(dsB);
           gvthread.DataSource = dsCommon;
           gvthread.DataBind();
      }
return;
}


这篇关于如何通过两个数据集线程填充GridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆