Exception “Procedure or function expects parameter, which was not supplied.” thrown even after supplying the parameter

I am trying insert some entries in the database using a stored procedure which is called by a C# method as shown below:

public int addProfile(UserProfile NewUserPro)
    DataSet ds = ExecuteStoredProcedure("AddNewPro", new SqlParameter[]{
                new SqlParameter("@UserID", NewUserPro.UsrId),
                new SqlParameter("@Type", NewUserPro.Type),
                new SqlParameter("@Phone", NewUserPro.Phone),
                new SqlParameter("@Name", NewUserPro.Name),
                new SqlParameter("@FatherName", NewUserPro.FatherName),
                new SqlParameter("@GroupID", NewUserPro.GroupID),
                new SqlParameter("@IsPublic", 0)});
            return int.Parse(ds.Tables[0].Rows[0][0].ToString());

ExecuteStoredProcedure() is a C# method created by me. It executes specified stored procedure and returns the output as a DataSet. This is the definition of that function:

  • How to make CREATE OR REPLACE VIEW work in SQL Server?
  • Date format in SQL Server
  • SQL Server : convert Julian Date to YYYY-MM-DD
  • What is the equivalent of 'describe table' in SQL Server?
  • Creating SQL constraint with possible circular dependencies
  • SQL - Query to seperate single column and create new columns based on column data
  • public DataSet ExecuteStoredProcedure(string ProcedureName, SqlParameter[] Parameters)
             using (SqlCommand com = new SqlCommand("[dbo]." + ProcedureName))
                  com.CommandType = CommandType.StoredProcedure;
                  foreach (SqlParameter sp in Parameters)
                  return SelectDataSet(com);
        catch (Exception e)
            throw e;

    As you can see in addProfile() method I am already providing @IsPublic parameter, but it’s still throwing following exception:

    Procedure or function ‘AddNewPro’ expects parameter ‘@IsPublic’,
    which was not supplied.

    @IsPublic parameter is an int parameter that saves value to [IsPublic] field which is an int field in a table with null allowed.

    UPDATE 1

    I am including the input parameters of the stored procedure. I think that will be enough? If you want I can include complete stored procedure but it’s a lengthy code and due to some confidentiality reasons I have to cut some lines.

    ALTER PROCEDURE [dbo].[AddNewPro]
        @UserID int,
        @Name NVARCHAR(MAX),
        @Type int,
        @Phone VARCHAR(MAX),
        @GroupID int,
        @FatherName VARCHAR(MAX),
        @IsPublic int

    UPDATE 2

    Ok I found a little hint to the solution. When I put the breakpoint on the first line of ExecuteStoredProcedure, I found that its getting the value of @IsPublic as null. But I provided the value while adding the parameters. Why this is happening?

  • .Net SQL Server Database Monitoring - Insert, Update, Delete
  • Wrapping system procedure in View or Stored Procedure
  • Error at the transport level when sending a request to the server
  • how to retrieve data from database to word document . net
  • 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'
  • Stopping .NET app's SQL Server DB being modifiable via Access using ODBC?
  • One Solution collect form web for “Exception “Procedure or function expects parameter, which was not supplied.” thrown even after supplying the parameter”

    sqlparameter reads zero as an object.

    Be careful to used zeroes, read this post link

    Must convert zero to integral type first .
    Your code should look like this.

    new SqlParameter("@IsPublic", Convert.ToInt32(0));
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.