我想将整数值传递给正在执行 SqlDataReader 的 SqlParameter,但是当我传递整数值时,它说,没有提供参数,下面是我的代码:
Common SqlDataReader Function
public static SqlDataReader ExecuteReader(string procedure, SqlParameter[] parameters, CommandType commandType)
{
SqlDataReader reader = null;
SqlConnection connection = new SqlConnection(connectionString);
using (SqlCommand command = new SqlCommand(procedure, connection))
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
if (parameters != null)
{
if (commandType == CommandType.StoredProcedure)
command.Parameters.AddRange(parameters);
}
reader = command.ExecuteReader(CommandBehavior.CloseConnection);
}
return reader;
}
调用代码:
SqlDataReader obj = SqlHelper.ExecuteReader("sp_TheWireUser", new SqlParameter[] { new SqlParameter("@USERID", Convert.ToInt32(1)), new SqlParameter("@ROLEID", Convert.ToInt32(6)) }, System.Data.CommandType.StoredProcedure);
Response.Write(obj.HasRows);
我也尝试1
作为参数输入,"1"
但都不起作用
ALTER PROCEDURE [dbo].[sp_TheWireUser]
@USERID INT,
@RoleID INT
AS
BEGIN
SELECT USR.USERID FROM Users USR
INNER JOIN UserRoles UR
ON USR.UserID = UR.UserID
INNER JOIN Roles R
ON UR.RoleID = R.RoleID
WHERE R.RoleID = @RoleID
AND USR.UserID = @USERID
END