troubleshooting Question

issue with Update to SQL using AddWithValue in C#

Avatar of Simon Cripps
Simon CrippsFlag for United Kingdom of Great Britain and Northern Ireland asked on
C#Microsoft SQL Server 2008ASP.NET
6 Comments1 Solution578 ViewsLast Modified:
Hi,
newly converting over to C# from VB and having an issue with writing an update using an SQL stored procedure. I am getting the follwing issue:
System.Data.SqlClient.SqlException: Procedure or function 'SPAWCampaignUpdate' expects parameter '@CampaignID', which was not supplied.
I have stepperd trought the execution of the programme and all appears OK and all appears OK.
The command text for SQLCmd  is as expected "SPAWCampaignUpdate"
There are 7 parameters supplied and one of them is called @CampaignID with the value I expected supplied by campaign.id.
in the stored procedure the CampaignID is defined as int and in the mapped in the table to a field defined as an integer as well. I have tried with both .AddWithValue("CampaignID", and .AddWithValue("@CampaignID"
Any suggestions (cade attached below)

SqlCommand SQLCmd = new SqlCommand("SPAWCampaignUpdate", con);
               SQLCmd.Parameters.AddWithValue("CampaignID", campaign.id);
               SQLCmd.Parameters.AddWithValue("campaignname", campaign.name);
               SQLCmd.Parameters.AddWithValue("campaignstatus", campaign.status);
               SQLCmd.Parameters.AddWithValue("campaignservingStatus", campaign.servingStatus);
               SQLCmd.Parameters.AddWithValue("campaignstartDate", campaign.startDate);
               SQLCmd.Parameters.AddWithValue("campaignendDate", campaign.endDate);
               SQLCmd.Parameters.AddWithValue("campaignbudget", System.Convert.ToString(campaign.budget));
                   try
                    {
                        SQLCmd.Connection.Open();
                        SqlDataReader UpdateRecs;
                        UpdateRecs = SQLCmd.ExecuteReader();
                        SQLCmd.Connection.Close();
                        SQLCmd.Connection.Dispose();
                    }
                   catch (Exception ex)
                   {
                   }

The Stored Procedure is
ALTER PROCEDURE dbo.SPAWCampaignUpdate
	@CampaignID int,
	@campaignname nvarchar (100),
	@campaignstatus nvarchar (10),
	@campaignservingStatus nvarchar (10),
	@campaignstartDate date,
	@campaignendDate date,
	@campaignbudget int
	
AS UPDATE AWCampaign
	SET AWCname = @campaignname, AWCstatus = @campaignstatus, AWCServingStatus = @campaignservingStatus, AWCStartDate = @campaignstartDate, AWCEndDate = @campaignendDate, AWCBudget = @campaignbudget
WHERE (AWCCampaignID = @CampaignID)
	RETURN
ASKER CERTIFIED SOLUTION
Carl Tawn
Senior Systems and Integration Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros