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

  • Home
  • SEARCH
  • 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 837233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:06:48+00:00 2026-05-15T05:06:48+00:00

I am trying to use a Stored Procedure which takes two parameters (login, pw)

  • 0

I am trying to use a Stored Procedure which takes two parameters (login, pw) and returns the user info.

If I execute the SP manually, I get

Session_UID   User_Group_Name      Sys_User_Name    
------------------------------------ -------------------------------------------------- -
NULL            Administrators       NTMSAdmin
No rows affected.
(1 row(s) returned)
@RETURN_VALUE = 0
Finished running [dbo].[p_SYS_Login].

But with the code below, I only get the return value.
do you know how to get the other values shown above like
Session_UID, User_Group_Name, and Sys_User_Name ?

if you see the commented part below code. I tried to add some output parameters but it doesn’t work with incorrect number of parameters error.

            string strConnection = Settings.Default.ConnectionString;            
            using (SqlConnection conn = new SqlConnection(strConnection))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    SqlDataReader rdr = null;
                    cmd.Connection = conn;
                    cmd.CommandText = "p_SYS_Login";
                    //cmd.CommandText = "p_sys_Select_User_Group";
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter paramReturnValue = new SqlParameter();
                    paramReturnValue.ParameterName = "@RETURN_VALUE";
                    paramReturnValue.SqlDbType = SqlDbType.Int;
                    paramReturnValue.SourceColumn = null;
                    paramReturnValue.Direction = ParameterDirection.ReturnValue;

                    //SqlParameter paramGroupName = new SqlParameter("@User_Group_Name", SqlDbType.VarChar, 50);
                    //paramGroupName.Direction = ParameterDirection.Output;

                    //SqlParameter paramUserName = new SqlParameter("@Sys_User_Name", SqlDbType.VarChar, 50);
                    //paramUserName.Direction = ParameterDirection.Output;

                    cmd.Parameters.Add(paramReturnValue);

                    //cmd.Parameters.Add(paramGroupName);
                    //cmd.Parameters.Add(paramUserName);

                    cmd.Parameters.AddWithValue("@Sys_Login", textUserID.Text);
                    cmd.Parameters.AddWithValue("@Sys_Password", textPassword.Text);

                    try
                    {
                        conn.Open();
                        object result = cmd.ExecuteNonQuery();
                        int returnValue = (int)cmd.Parameters["@RETURN_VALUE"].Value;
                        if (returnValue == 0)
                        {
                            Hide(); 
                            Program.MapForm.Show();
                        }
                        else if (returnValue == 1)
                        {
                            MessageBox.Show("The username or password you entered is incorrect", "NTMS Login", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (returnValue == 2)
                        {
                            MessageBox.Show("This account is disabled", "NTMS Login", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else                         
                        {
                            MessageBox.Show("Database error. Please contact administrator", "NTMS Login", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    catch (Exception ex)
                    {
                        string message = ex.Message;
                        string caption = "MAVIS Exception";
                        MessageBoxButtons buttons = MessageBoxButtons.OK;

                        MessageBox.Show(
                            message,
                            caption,
                            buttons,
                            MessageBoxIcon.Warning,
                            MessageBoxDefaultButton.Button1);
                    }                    
                }
            }

Thanks for your help.

  • 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-05-15T05:06:49+00:00Added an answer on May 15, 2026 at 5:06 am

    You need to call ExecuteReader method on the cmd object and read the output by using Read method of the SqlDataReader class.

    Here is an example: SqlDataReader.Read method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple stored procedure which I can use to write
I am trying to use a stored procedure in the entity framework that returns
I am trying to create stored procedure which will decide which language to use
I am trying to use the stored procedure mapping feature in Entity Framework to
I'm trying to pass a table name into my mysql stored procedure to use
I am trying to write a stored procedure that takes a table name as
I'm using an Oracle database(10g) which contains a stored procedure called Foo. Foo takes
I am trying to write a stored procedure in MySQL which will perform a
I have a stored procedure which calculates the distance between two coordinate pairs as
I am trying to create a simple stored procedure in PostgreSQL within which I

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.