0

I have written a function in Datalayer and is accessed in the business layer and it is throwing an exception in business layer as Procedure or function 'create_UR_Map' expects parameter '@User_Id', which was not supplied.

 I have showed the code below

1)Data layer

public int fninsertuser_role_map(UserMaster u, int[] role, int i)
{
    SqlConnection Con = new SqlConnection(str);
    Con.Open();
    transaction = Con.BeginTransaction();
    int result=0;

    for (int a = 0; a < i; a++)
    {
        SqlCommand Cmd = new SqlCommand("create_UR_Map", Con,transaction);
        Cmd.CommandType = CommandType.StoredProcedure;
        Cmd.Parameters.Clear();
        Cmd.Parameters.AddWithValue("@User_Id", u.UserName);
        Cmd.Parameters.AddWithValue("@Role_Id", role[a]);
        Cmd.CommandType = CommandType.Text;

       result = Cmd.ExecuteNonQuery();
    }
    transaction.Commit();
    return result;
}

2)Business layer

 public int fninsertuser_role_map(UserMaster ua,int []role,int i)
 {
    //  Connection connect = new Connection();
    try
    {
        return cs.fninsertuser_role_map(ua, role, i);

    }
    catch (Exception e)
    {
        throw e;
    }
    finally
    {
        cs = null;
    }

}

3)Stored procedure

  USE [RHK_HIS]
  GO
 SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
 ALTER PROCEDURE [dbo].[create_UR_Map]
  @User_Id varchar(15),
  @Role_Id int
   AS
    BEGIN
insert into User_Role_Map (User_Id,Role_Id) values (@User_Id,@Role_Id)  
END

4)table

    User_Role_Map
     User_I      varchar(15)
Role_Id      int    

I have googled the error and found out that if parameters passed are unequal then the above error will come.But I have passed all the parameters still its thrpwing the exception.any help are appreciated

1 Answer 1

1

Remove following code in your data layer since you are calling a stored procedure.

Cmd.CommandType = CommandType.Text;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.