2011-06-22 15 views
0

私は条件に基づいて2つの以上のテーブルのデータを取得していますので、私はこのようなSQL server2005にカーソルを書いています:SQL Server 2005のカーソル値をASP.NET 2.0のgridviewに取得する方法は?

create PROC [dbo].[uspCustomerInvoiceGetlist] 
    @CustomerID varchar(20) 
AS 
BEGIN 

    SELECT DeleteStatus,InvoiceID,CONVERT(varchar(16),CreationDate,101) + ' ' + 
     CONVERT(varchar(16),CreationDate,8) as CreationDate,AccountNumber,Sum(Amount) as Amount from tblInvoiceDetails where [email protected] Group By InvoiceID,CreationDate,AccountNumber,DeleteStatus 
END 

alter procedure uspCustomerInvoiceGetlist1(@CustomerID varchar(50)) as 
    Begin 
     Declare @InvoiceID int, @Balance float 
     Declare MyCur Cursor for select InvoiceID from tblInvoiceHeader where [email protected] 
     Open MyCur 
     Fetch next from mycur into @InvoiceID 
     While @@Fetch_Status=0 
     Begin 
     set @Balance=(select sum(Balance) from tblInvoicePaymentDetails where [email protected] and [email protected]) 
print @Balance  
if @Balance!=0 

     SELECT h.DeleteStatus,h.InvoiceID,CONVERT(varchar(16),h.CreationDate,101) + ' ' + 
     CONVERT(varchar(16),h.CreationDate,8) as CreationDate,h.AccountNumber,Sum(h.Amount) as Amount, @Balance as Balance from tblInvoiceDetails h inner join tblInvoicePaymentDetails p on h.CustomerID=p.CustomerID and [email protected] 
    Group By h.InvoiceID,h.CreationDate,h.AccountNumber,h.DeleteStatus 
else 
SELECT DeleteStatus,InvoiceID,CONVERT(varchar(16),CreationDate,101) + ' ' + 
     CONVERT(varchar(16),CreationDate,8) as CreationDate,AccountNumber,Sum(Amount) as Amount, 0 as Balance from tblInvoiceDetails where [email protected] and [email protected] Group By InvoiceID,CreationDate,AccountNumber,DeleteStatus 

      Fetch Next From MyCUr into @InvoiceID 
     End 
     Close Mycur 
     Deallocate Mycur 
    End 

出力はそのような正しいです(条件2に基づいて2つの出力がもっとある)

Status InvoiceID  Date     account no Amount  Balance 
    1 1009  06/21/2011 10:22:15  10009 450  350 

Status InvoiceID  Date     account no Amount  Balance 
1 1010  06/21/2011 10:22:33  100000  690   0 

しかし、私は、ASP.NET 2.0でのグリッドビュー内のすべての値(両方)に結合することができます。どのように可能ですか?

答えて

0

フロントエンドでは、2つのDataTableを取得します。 これら2つのDataTableを1つにまとめてください。 DataViewをGridViewにバインドします。 は次のようにマージ:

dt1.Merge(dt2);  //dt1 is the DataTable 1 and dt2 is the DataTable 2 

は、DataSetとしてテーブルのセットを取得し、ループのために使用してマージ:私は以下のコードを与えている:

DataTable dtmerge = new DataTable(); 
    for (int i = 0; i < ds.Tables.Count; i++)    // ds is the DataSet 
    { 
     dtmerge.Merge(ds.Tables[i]); 
    } 
+0

仮定するさらに2つのテーブルが先生どのようにそれが可能な条件に基づいて表示されます – hmk

+0

あなたはすべてのDataTableをマージして同じことに従います。 – thevan

+0

こんにちは。私は私の答えを編集しました。ただこれに従ってください。これはあなたを助けるかもしれません。 – thevan

関連する問題