3
設置空的結果獲取列標題我運行MS SQL的存儲過程。當我在MS SQL Server Management Studio下運行這些過程時,他們總是返回列標題。我正在嘗試在Delphi程序中獲得此功能。目前,如果數據集沒有行,則不會返回標題。用Delphi 7,TADOStoredProc,TADODataset和串格:從德爾福ADOStoredProc
ADOStoredProc1.ObjectView := True;
ADOStoredProc1.Open;
ADODataSet1.Recordset := ADOStoredProc1.Recordset;
// process the first dataset, which contains rows
if not ADODataSet1.IsEmpty then
begin
AdvGridWorkbook1.ActiveSheet := 0;
// build grid header
SetupHeader;
// build grid detail
SetupDetail;
end
else
begin
Memo1.Lines.Add('Returned empty data set for Mapping');
end;
// load the next dataset. no data rows but MS Studio shows column headers
ADODataSet1.Recordset := ADOStoredProc1.NextRecordset(RecordsAffected);
if not ADODataSet1.IsEmpty then // tests as empty
begin
AdvGridWorkbook1.ActiveSheet := 1;
// build grid header - none are returned as IsEmpty = True
SetupHeader;
// build grid detail
SetupDetail;
end
else
begin
// this message is added to my memo field.
Memo1.Lines.Add('Returned empty data set for Labor');
end;
ADODataSet1.Close;
ADOStoredProc1.Close;
有誰知道MS是怎麼列標題回來?
存儲過程是:
USE [NG_Test]
GO
/****** Object: StoredProcedure [dbo].[NG_Checks] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[NG_Checks]
@fiscal_month_year nvarchar(50)
AS
BEGIN
declare @production_date datetime
declare @start_date datetime
declare @end_date datetime
select @production_date = ng_production_release_date
from ng_common_global_provisioning
select @start_date = start_date, @end_date = end_date
from ng_common_accounting_fiscal_month
where fiscal_month_year = @fiscal_month_year
-- this is the 1st dataset returned
select b.company, b.wo_type, b.wo_code
from ng_accounting_mapping_ng_wo_2_gp b
where wo_code not in (select wo_code from ng_wo_codes a)
-- this is the 2nd dataset returned
select a.wo_display_id, a.wo_code, a.labor_revenue, a.labor_cost,
a.create_date, a.completion_date, a.finalizing_date, a.wo_status
from ng_wo_header a, ng_wo_labor_rates b
where a.wo_code = b.work_order_code
and a.company = b.company
and a.wo_type = b.work_order_type
and a.wo_type in ('RO', 'BS')
and a.labor_revenue is not null and a.labor_revenue <> 0
and a.labor_cost is not null and a.labor_cost <> 0
and a.create_date > @start_date
and a.create_date < @end_date
and a.create_date > @production_date
END
OK,不知道這是否是猶太教,但我刪除了測試中爲IsEmpty和網格現在顯示標題!它讓我感到數據在那裏(列標題),但它測試爲空。我猜「空」意味着沒有行,不是缺乏實際的信息。 – worker17
就像你說的!從參考文獻中,['IsEmpty'](http://docwiki.embarcadero.com/Libraries/XE2/en/Data.DB.TDataSet.IsEmpty)指示數據集是否包含任何記錄。所以它僅適用於數據集行,而不適用於其字段名稱。無論如何,你已經解決了你的問題,所以公平地發佈和['接受你自己的答案'](http://blog.stackoverflow.com/2009/01/accept-your-own-answers/)。未來的訪客可以快速找到同樣問題的答案。謝謝! – TLama