系统错误:无效的对象名称'数据库名称'

时间:2017-10-13 02:30:21

标签: c# sql visual-studio-2010 ssms

我正在尝试运行一个程序,该函数将报告导出到excel文件。到目前为止,当我点击生成时,它适用于其他类型的报告,但在这个特定的报告,游戏交易报告,我收到错误:"系统错误:无效的对象名称' GCVS2.dbo.GameTrx&# 34 ;.这是这种情况的代码:

db.Open();
command = new SqlCommand("M_RPT_GameTransactionReport", db);
strControlValue = GetControlValue(pnlRecordRange, "useDateTimeFrom", ControlType.LabelDateTimePickerFrom);
if (strControlValue != null)
{
    // dtFrom = DateTime.Parse(DateTime.Parse(strControlValue).ToShortDateString());
    dtFrom = Convert.ToDateTime(strControlValue);

}

strControlValue1 = GetControlValue(pnlRecordRange, "useDateTimeTo", ControlType.LabelDateTimePickerTo);
if (strControlValue1 != null)
{
    dtTo = Convert.ToDateTime(strControlValue1);
    // if (dtTo != DateTime.MinValue)
    //     dtTo = MaxTimeOfDate(dtTo);
}

command.Parameters.AddWithValue("@EventCode",strEvCode );
command.Parameters.AddWithValue("@PromotionBenefitCode",strPromotionBenefitCode );
command.Parameters.AddWithValue("@DtFrom",dtFrom );
command.Parameters.AddWithValue("@DtTo",dtTo );
command.Parameters.AddWithValue("@CardIdFrom",strCardIDFrom );
command.Parameters.AddWithValue("@CardIDTo",strCardIDTo );
command.Parameters.AddWithValue("@SerialNo",strSerialNo );
command.Parameters.AddWithValue("@Status",strStatus );




command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 0;
dr = command.ExecuteReader();
ExportExcel(dr);
db.Close();

我该如何解决这个问题?

编辑:下面是GameTransactionReport存储过程的sql脚本:

   ` CREATE       PROCEDURE [M_RPT_GameTransactionReport]
    @EventCode varchar(8),
    @PromotionBenefitCode varchar (100),
    @CardIDFrom varchar(50),
    @CardIDTo varchar(50),
    @SerialNo varchar(15),
    @DtFrom datetime,
    @DtTo datetime,
    @Status CHAR(1)
    AS`

    SET NOCOUNT ON`

`SELECT G.[GameTrxID]
      ,G.[EventCode]
      ,PE.[Description]
      ,G.[PromotionBenefitCode]
      ,G.[GameSetupID]
      ,GE.[GameSetupDescription]
      ,G.[GameInventoryID]
      ,G.[GameUnlimitedInventoryID]
      ,G.[CardId]
      ,G.[VisiblePoint]
      ,G.[HiddenPoint]
      ,G.[LoyaltyPoint]
      ,G.[VisiblePointEarn]
      ,G.[TradingDate]
      ,G.[VoucherSerialNo]
      ,G.[Winner]
      ,G.[TerminalID]
      ,T.[ComputerName]
      ,G.[CreateBy]
      ,G.[CreateDate]
      ,G.[Status]
      ,G.[CancelReason]
      ,G.[LastChangeBy]
      ,G.[LastChangeDate]`
      `


`FROM [GCVS2].[dbo].[GameTrx] G,PromotionEvent PE, GameEventSetup GE ,
    Terminal T with (nolock)`

`WHERE
G.TerminalID =T.TerminalID
AND
G.EventCode = PE.EventCode
AND
G.GameSetupID = GE.GameSetupID
AND 
(@DtFrom IS NULL OR 
G.[TradingDate] >= @DtFrom )
AND 
(@DtTo IS NULL OR 
G.[TradingDate] <= @DtTo)
AND
(@EventCode = '' OR (G.EventCode = @EventCode))
AND
(@PromotionBenefitCode = '' OR (G.PromotionBenefitCode = @PromotionBenefitCode))
AND
(@CardIDFrom = '' OR (G.CardID >= @CardIDFrom))
AND
(@CardIDTo = '' OR (G.CardID <= @CardIDTo))
AND
(@SerialNo = '' OR (G.VoucherSerialNo = @SerialNo))
AND 
(@Status = '' OR (G.Status = @Status))`

1 个答案:

答案 0 :(得分:0)

修改存储过程并更改以下行:

FROM [GCVS2].[dbo].[GameTrx]

 FROM [dbo].[GameTrx]