错误消息:找不到表0

本文关键字:找不到 消息 错误 | 更新日期: 2023-09-27 17:59:03

首先,我想为这篇文章的篇幅道歉。但我想让你们了解整个问题。

我必须合并三个数据集(dsGetFormdsmedication_detailsdsbroadband_details),并在表中显示结果。

dsbroadband_details有时包含行,有时不包含行。

这就是我现在用来合并数据集的方法。

if (dsGetForm != null && dsmedication_details != null && dsbroadband_details != null)
{
   dsGetForm.Tables[0].Merge(dsmedication_details.Tables[0]);
   dsGetForm.Tables[0].Merge(dsbroadband_details.Tables[0]);
}
else if (dsGetForm == null && dsmedication_details != null)
{
   dsGetForm = dsmedication_details;
}
else if (dsGetForm == null && dsbroadband_details != null )
{
   dsGetForm = dsbroadband_details;
} 

问题是,当存储过程的结果为空时,用于填充数据集dsbroadband_details的存储过程(SP)会给我这个错误消息

错误消息:找不到表0。描述:未处理的异常在执行当前web请求。请查看堆栈跟踪以获取详细信息关于错误及其位置源自代码。

异常详细信息:System.ServiceModel.FFaultException `1[[System.ServiceModel.ExceptionDetail,System.ServiceModel,版本=3.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]:找不到表0

这是我的存储过程

Alter Procedure dbo.OEA_SP_GET_BROADBAND ( 
                @appid    NUMERIC,
                @clientid NUMERIC,
                @Lang Varchar(10))
AS 
   SET nocount  ON 
   BEGIN 
  declare @PIName as varchar(100)
  declare @username as varchar(20)
  declare @pform_id as varchar(20)
  declare @pform_desc as varchar(100)
  declare @userid varchar(20)
  declare @msn tinyint
  set @PIName=''
  if exists(SELECT app_id from ext_well_new_programs (nolock) where app_id=@appid and new_prog_id='BB' and status='A')
  begin
      select @PIName=dbo.oea_fn_fetch_fullname(@appid,primary_msn,1,@lang,@clientID) 
          from app_application with (nolock)
      where app_id = @appid
  end 
  if @PIName <> ''
  begin
    select Distinct @username = dbo.oea_fn_fetch_caaname(prog.last_update_id, 30000) 
            from app_prog_submission prog (nolock) 
            where app_id = @appid
            select @userid = user_id, @msn = primary_msn 
            from app_application (nolock) 
            where app_id = @appid
            set @pform_id = 'learnmore'
    set @pform_desc = 'Cash Back for Broadband at Home'
    select @PIName as mem_name, @appid as app_id, @username as username, @pform_id as pform_id, @pform_desc as pform_desc, 0 as noncust, @userid as userid, @msn as msn
 END
     End

我想,我需要在if @PIName <> ''条件之后添加一个else条件。

我的问题是,其他条件应该是什么?

由于我只需要if @PIName <> ''的select语句(在末尾)的值当这个条件成立时,我有点困惑,那还应该是什么?

非常感谢您的帮助。

错误消息:找不到表0

在我看来,有些情况下SP没有返回任何结果,因此没有"表0"。我宁愿构造一个@results内存表,在该表中插入数据(如果有的话),并在退出SP之前执行最后的select mem_name, app_id, ... from @results。或者任何其他实际返回结果集的SQL构造,即使是空的。