附近有語法錯誤','異常,當應用程序設置爲運行出現。
在SQL Server Management Studio查詢運行良好。但它在應用程序設置爲運行時引發異常。
存儲過程:
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
GO
ALTER PROCEDURE dbo.[ USP_GET_MONTH_WISE_PENDING_DETAILS]
@MONTH INT = 4,
@YEAR INT = 2017
AS
BEGIN
SET NOCOUNT ON;
SELECT
P.PbsName, PC.CauseName,
dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.DayFrom) + N'/' + dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.MonthFrom) + N'/' +
dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.YearFrom) + N'থেকে' + dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.DayTo) + N'/' +
dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.MonthTo) + N'/' + dbo.F_CONVERT_ENG_NUMBER_TO_BNG(PCI.YearTo) 'Date',
PCI.Remarks
FROM
Pbs P
INNER JOIN
ProbableConnectionInfo PCI ON PCI.PbsId = P.PbsId
INNER JOIN
ConnectionPendingCause CPC ON PCI.Id = CPC.ProbableConnectionId
INNER JOIN
PendingCause PC ON CPC.PendingCauseId = PC.Id
WHERE
PCI.MONTH = @MONTH AND
YEAR = @YEAR AND
CPC.PendingNumber > 0;
SELECT
dbo.F_CONVERT_ENG_NUMBER_TO_BNG(SUM(IC.Pending)) 'PendingApplication',
dbo.F_CONVERT_ENG_NUMBER_TO_BNG(SUM(IC.loadNeed)) 'AppliedLoadAmount'
FROM
IndustrialConnection IC
INNER JOIN
ProbableConnectionInfo PCI ON IC.ProbableConnectionId = PCI.Id
WHERE
PCI.MONTH = @MONTH AND YEAR = @YEAR
GROUP BY
PCI.PbsId;
SET NOCOUNT OFF;
END;
,這裏是哪裏出了問題被顯示出來:
public static DataTable GetDataByStoredProcedure(string spName, List<SqlParameter> pars = null)
{
sqlConnection.Open();
var sqlCommand = new SqlCommand(spName, sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
if (pars != null)
{
sqlCommand.Parameters.AddRange(pars.ToArray());
}
var dataReader = sqlCommand.ExecuteReader();
var dt = new DataTable("Command");
dt.Load(dataReader);
//sqlConnection.Close();
return dt;
}
這裏是我使用的方法:
public void ShowPendingIndustrialInfo(string exportType, int year, int month)
{
List<SqlParameter> pars = new List<SqlParameter>();
SqlParameter p1 = new SqlParameter("@month", SqlDbType.Int);
p1.Value = month;
SqlParameter p2 = new SqlParameter("@year", SqlDbType.Int);
p2.Value = year;
pars.Add(p1);
pars.Add(p2);
var data = SPService.GetDataByStoredProcedure("USP_GET_MONTH_WISE_PENDING_DETAILS",pars);
ReportHelper.ShowReport(data, exportType, "rptPendingDetails.rpt");
}
我注意到你已經改變了sp的名字。現在它讀取爲* USP_GET_MONTH_WISE_PENDING_DETAILS *。哪一個是正確的?你可以用調試器檢查傳遞給你的方法的參數的值是什麼? – Steve
參數作爲「USP_GET_MONTH_WISE_PENDING_DETAILS4,2017」(月,年)傳遞給我認爲正確的方法。但程序沒有找到。 @Steve –
如果你的存儲過程被命名爲USP_GET_MONTH_WISE_PENDING_DETAILS但你通過USP_GET_MONTH_WISE_PENDING_DETAILS,4,2017然後難怪如果數據庫找不到名稱 – Steve