Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:34:06+00:00 2026-06-10T03:34:06+00:00

i want to pass integer value to the SqlParameter which is executing an SqlDataReader,

  • 0

i want to pass integer value to the SqlParameter which is executing an SqlDataReader, but when i pass integer value it says, the Parameter is not supplied, below is my code:

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;
    }

Calling code:

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

i tried entering 1 as a parameter also "1" but all does not work

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:34:08+00:00Added an answer on June 10, 2026 at 3:34 am

    Why are you converting 1 to Integer by calling Convert.ToInt32() .1 is already integer. So you do not need to do that.

    SqlDataReader obj = ExecuteReader("sp_TheWireUser", 
                    new SqlParameter[] { 
                        new SqlParameter("@USERID", 1),
                        new SqlParameter("@ROLEID", 6)
                    },
                    System.Data.CommandType.StoredProcedure);
    

    This code should not throw any compile time errors. If you are getting a runtime exception, The possible reason is your Stored Procs paramter’s data type is different than what you are passing here. It should be Integer as per your code.

    Note : Hope you are closing the DataReader after use.

    EDIT : You have to tell the CommandType

     using (SqlCommand command = new SqlCommand(procedure, connection))
     {
        command.CommandType = commandType; //passed from your method parameter
        //your remaining code
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a code in which i want to pass integer value for
I want to pass an object (not just a string or integer) from a
hi i am using PHP i want to pass an integer value (1-12) and
I want to store integer value in label and to pass to another form.
I want to pass an integer value to a form in .Net so that
I want to pass an integer value from activity A to B, to C.
I want to pass an int value from my selector method, but the selector
here is my Problem, I want to pass the integer 1 when this canvas
I want to pass an ImageIcon instance by value as we know that by
I want to basically create a animation, and when I pass in an integer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.