I have been using a Stored Procedure created by our DB guy, who happens to be out of town for the next week. The SP used to work, but before he left, the DB guy edited the SP, causing my code to throw a server error: "Column name or number of supplied values does not match table definition". He claimed before he left the SP should mainly be the same, so I'm at a loss for why it's no longer matching.
Here is the c# code:
System.Data.SqlClient.SqlCommand objCmd = new
System.Data.SqlClient.SqlCommand("dci.webDonorStatistics", objConn);
objCmd.CommandTimeout = 950;
objCmd.CommandType = System.Data.CommandType.StoredProcedure;
objCmd.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@FiscalYear", 2018));
GridView1.DataSource = objCmd.ExecuteReader();
GridView1.DataBind();
Here is the declaration of the SP:
ALTER PROCEDURE [dci].[webDonorStatistics] @FiscalYear INT
AS
BEGIN
--DECLARE @FiscalYear INT = 2018
DECLARE
@StartDate DATE = CONVERT(DATE, '01-OCT-' + CONVERT(CHAR(4), @FiscalYear - 1))
, @EndDate DATE = DATEADD(DAY, -1, GETDATE())
IF @EndDate >= CONVERT(DATE, '30-SEP-' + CONVERT(CHAR(4), @FiscalYear))
SELECT @EndDate = CONVERT(DATE, '30-SEP-' + CONVERT(CHAR(4), @FiscalYear))
ELSE
SELECT @EndDate = DATEADD(DAY, -1, CONVERT(DATE, '01-' + DATENAME(MONTH, GETDATE()) + '-' + CONVERT(CHAR(4), YEAR(GETDATE())))) -- End of previous month
IF DATEDIFF(DAY, @StartDate, @EndDate) < 0
SELECT @EndDate = GETDATE()
BEGIN TRY
DROP TABLE #webDonorStatistics
END TRY
BEGIN CATCH
END CATCH
Any help would be greatly appreciated. Thanks in advance.
INSERTwithout the correct number of columns specified. Are you sure this is where the exception is thrown?tryblock. Are you sure you're talking to the right server & database? I would roll the sproc back to the previous version (surely, happily saved in source control) to fix your error, and compare the two versions.BEGINat the top of the code, your local variables aren't being used for anything, and your calling code is clearly expecting a result set.