使用Delphi ADOStoredProc从空结果集中获取列标题

使用Delphi ADOStoredProc从空结果集中获取列标题,delphi,stored-procedures,Delphi,Stored Procedures,我使用MS SQL运行了几个存储过程。当我在MS SQL Server Management Studio下运行这些过程时,它们总是返回列标题。我也在尝试在Delphi程序中获得此功能。当前,如果数据集没有行,则不会返回任何标题。使用Delphi 7、TadoDataProc、TADODataset和字符串网格: ADOStoredProc1.ObjectView := True; ADOStoredProc1.Open; ADODataSet1.Recordset := ADOStoredPr

我使用MS SQL运行了几个存储过程。当我在MS SQL Server Management Studio下运行这些过程时,它们总是返回列标题。我也在尝试在Delphi程序中获得此功能。当前,如果数据集没有行,则不会返回任何标题。使用Delphi 7、TadoDataProc、TADODataset和字符串网格:

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 

IsEmpty方法测试包含数据的实际记录,因此它不计算阻止调用setupHeader方法的列标题/字段名

只需删除对IsEmpty的调用或将其移动:

AdvGridWorkbook1.ActiveSheet := 0;
// build grid header
SetupHeader;

// build grid detail
if not ADODataSet1.IsEmpty then
begin
  SetupDetail;
end
else
begin
  Memo1.Lines.Add('Returned empty data set for Mapping');
end;

好的,我不知道这是否符合犹太教,但我删除了对IsEmpty的测试,网格现在显示标题!数据在列标题中,但它测试为空,这让我很恼火。我猜空意味着没有行,不是缺少实际信息。正如你所说的!从引用中,指示数据集是否不包含任何记录。因此,它仅适用于数据集行,而不适用于其字段名。不管怎样,你已经解决了你的问题,所以发布和发布是公平的。它可以帮助未来的访问者快速找到相同问题的答案。谢谢谢谢我已经找到了,现在就可以了。