Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am running into an issue where the error does not make sense. The immediate window says that the parameter is not missing but the debugger says that it is missing.

Error: Procedure or function 'cpWeeklyPharmDataintDrvr' expects parameter '@companyID', which was not supplied.

Immediate Window:
?cmd.Parameters["@companyID"].Value
1356

C#
SqlCommand cmd = new SqlCommand("cpWeeklyPharmDataintDrvr", sqlC);

            SqlConnection sqlC = new SqlConnection(ConfigurationManager.ConnectionStrings["Reports"].ToString());
            SqlCommand cmd = new SqlCommand("cpWeeklyPharmDataintDrvr", sqlC);

            sqlC.Open();

            cmd.Parameters.Add(new SqlParameter("@companyID", SqlDbType.Int)).Value = Master.CompanyId;
            cmd.Parameters.Add(new SqlParameter("@sStartDate", SqlDbType.NVarChar, 30)).Value = Master.StartDate;
            cmd.Parameters.Add(new SqlParameter("@sEndDate", SqlDbType.NVarChar, 30)).Value = Master.EndDate;
            if (Master.RegionId > 0)
                cmd.Parameters.Add(new SqlParameter("@region", SqlDbType.Int)).Value = Master.RegionId;
            if (Master.DistrictId > 0)
                cmd.Parameters.Add(new SqlParameter("@district", SqlDbType.Int)).Value = Master.DistrictId;
            if (Master.StoreId > 0)
                cmd.Parameters.Add(new SqlParameter("@store", SqlDbType.NVarChar)).Value = Master.StoreId.ToString();

            SqlDataReader dR = cmd.ExecuteReader(); //This is where error occurs.
            DataTable d = new DataTable();
            d.Load(dR);

            sqlC.Close();
Posted
Updated 4-Oct-13 13:37pm
v4
Comments
Thanks7872 26-Sep-13 3:56am    
The conditions you have specified is wrong. It will result in error if any of the parameter is not supplied.
Kyle Gottfried 26-Sep-13 12:37pm    
Can you go into more detail?
Thanks7872 27-Sep-13 0:03am    
suppose your stored procedure requires companyID as parameter and if(Master.CompnayID>0) is not true,then that parameter will not be passed and you will obviously get an error.
Kyle Gottfried 4-Oct-13 19:32pm    
Code changed, still experiencing same error.

First Add...
C#
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CompanyID",CompanyID);
//add your other parameters also


May be you have forget to Declare @companyID
And Make sure You are dealing with SP like...

Stored Procedure
SQL
CREATE dbo.mySP
   @companyID INT,
   @companyName NVARCHAR
   <--Here You need to declare all parameters-->
AS
BEGIN
   INSERT INTO TBL VALUES(@companyID,@companyName)
END



Hope This Help
------------------
Pratik Bhuva
 
Share this answer
 
v2
Include the parameter @companyID in your Stored Procedure
 
Share this answer
 
just remove

if (Master.CompanyId > 0)

and check it
 
Share this answer
 
Mssing cmd.CommandType = CommandType.StoredProcedure;
 
Share this answer
 
hello professional

please try to one more time review as per your condition you know more then us to flow of your logic

but i think
Your stored proc cpWeeklyPharmDataintDrvr expects you to supply @companyID parameter.. which you have not.
and
You need to use SqlCommand.Parameters.AddWithValue:

happy to help!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900