Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with Stored Procedure's Return value

Problem with Stored Procedure's Return value

Scheduled Pinned Locked Moved C#
databasecsharphelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ronin1770
    wrote on last edited by
    #1

    Hi, I am using a Stored Procedure to validate Login Process: Stored Procedure is defined as follows : ---------------------------------------------------------- CREATE PROCEDURE spCheckLogin @LoginID char(20), @Pwd char(8), @Response int OUTPUT AS IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd) Return 1 ELSE Return 0 GO ---------------------------------------------------------- In C#, I am accessing this Stored Procedure as follows: try { string temp=""; //open the connection gvDatabase.scInventoryControl.Open(); //create the sql sql = "spCheckLogin"; //create command cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl); cmdLogin.CommandType=CommandType.StoredProcedure; cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20); cmdLogin.Parameters["@LoginID"].Value=log; cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8); cmdLogin.Parameters["@Pwd"].Value=p; cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4); cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output; Console.WriteLine("Data Access started"); cmdLogin.ExecuteNonQuery(); temp = cmdLogin.Parameters["@Response"].Value.ToString(); Console.WriteLine(temp); //clean up code cmdLogin.Dispose(); gvDatabase.scInventoryControl.Close(); Console.WriteLine("Data Access Closed"); } catch(Exception ex) { Console.WriteLine(ex.ToString() ); } ------------------------------------------------------------ However It doesn't print any values, although I values do exists in the table What am i doing wrong? ThANX in ADvance

    W D 2 Replies Last reply
    0
    • R ronin1770

      Hi, I am using a Stored Procedure to validate Login Process: Stored Procedure is defined as follows : ---------------------------------------------------------- CREATE PROCEDURE spCheckLogin @LoginID char(20), @Pwd char(8), @Response int OUTPUT AS IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd) Return 1 ELSE Return 0 GO ---------------------------------------------------------- In C#, I am accessing this Stored Procedure as follows: try { string temp=""; //open the connection gvDatabase.scInventoryControl.Open(); //create the sql sql = "spCheckLogin"; //create command cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl); cmdLogin.CommandType=CommandType.StoredProcedure; cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20); cmdLogin.Parameters["@LoginID"].Value=log; cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8); cmdLogin.Parameters["@Pwd"].Value=p; cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4); cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output; Console.WriteLine("Data Access started"); cmdLogin.ExecuteNonQuery(); temp = cmdLogin.Parameters["@Response"].Value.ToString(); Console.WriteLine(temp); //clean up code cmdLogin.Dispose(); gvDatabase.scInventoryControl.Close(); Console.WriteLine("Data Access Closed"); } catch(Exception ex) { Console.WriteLine(ex.ToString() ); } ------------------------------------------------------------ However It doesn't print any values, although I values do exists in the table What am i doing wrong? ThANX in ADvance

      W Offline
      W Offline
      woudwijk
      wrote on last edited by
      #2

      looks to me you got two thing mixed up. you should eighter change youre sql code to ======================= CREATE PROCEDURE spCheckLogin @LoginID char(20), @Pwd char(8), @Response int OUTPUT AS IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd) SET @Response=1 ELSE SET @Response=0 GO ======================== OR you should use something like this in youre code: ======================== string temp=""; //create the sql string sql = "spCheckLogin"; //create command cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl); cmdLogin.CommandType=CommandType.StoredProcedure; cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20); cmdLogin.Parameters["@LoginID"].Value=log; cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8); cmdLogin.Parameters["@Pwd"].Value=p; cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4); cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output; Console.WriteLine("Data Access started"); try { //open the connection gvDatabase.scInventoryControl.Open(); //use the connection temp=(string)cmdLogin.ExecuteScaler(); Console.WriteLine(temp); } catch(Exception ex) { Console.WriteLine(ex.ToString() ); } finally { //clean up code gvDatabase.scInventoryControl.Close(); Console.WriteLine("Data Access Closed"); } cmdLogin.Dispose(); ======================== i hope this helps. (p.s. i did not test above code) cookies are for eating, not for websites.

      1 Reply Last reply
      0
      • R ronin1770

        Hi, I am using a Stored Procedure to validate Login Process: Stored Procedure is defined as follows : ---------------------------------------------------------- CREATE PROCEDURE spCheckLogin @LoginID char(20), @Pwd char(8), @Response int OUTPUT AS IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd) Return 1 ELSE Return 0 GO ---------------------------------------------------------- In C#, I am accessing this Stored Procedure as follows: try { string temp=""; //open the connection gvDatabase.scInventoryControl.Open(); //create the sql sql = "spCheckLogin"; //create command cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl); cmdLogin.CommandType=CommandType.StoredProcedure; cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20); cmdLogin.Parameters["@LoginID"].Value=log; cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8); cmdLogin.Parameters["@Pwd"].Value=p; cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4); cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output; Console.WriteLine("Data Access started"); cmdLogin.ExecuteNonQuery(); temp = cmdLogin.Parameters["@Response"].Value.ToString(); Console.WriteLine(temp); //clean up code cmdLogin.Dispose(); gvDatabase.scInventoryControl.Close(); Console.WriteLine("Data Access Closed"); } catch(Exception ex) { Console.WriteLine(ex.ToString() ); } ------------------------------------------------------------ However It doesn't print any values, although I values do exists in the table What am i doing wrong? ThANX in ADvance

        D Offline
        D Offline
        dishanf
        wrote on last edited by
        #3

        Try... // Add the return value parameter SqlParameter param = m_oCommand.Parameters.Add( "RETURN_VALUE", SqlDbType.Int ); param.Direction = ParameterDirection.ReturnValue; D!shan

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups