2014-01-09 58 views
0

我曾经在数据层写入的功能并在业务层被访问,它是扔在业务层的异常作为Procedure or function 'create_UR_Map' expects parameter '@User_Id', which was not supplied.参数从存储过程传递错误到ASP.NET

I have showed the code below 

1)数据层

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)存储的业务层

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)步骤

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)表

User_Role_Map 
    User_I  varchar(15) 
Role_Id  int  

我用Google搜索了错误,并发现,如果传递的参数是不相等的,则上述错误将come.But我已经通过了所有的参数仍然是其thrpwing异常。任何帮助表示赞赏

回答

1

因为您正在调用存储过程,请删除数据层中的以下代码。

Cmd.CommandType = CommandType.Text;