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. .NET (Core and Framework)
  4. How 2 return a string value from sql server in SP?

How 2 return a string value from sql server in SP?

Scheduled Pinned Locked Moved .NET (Core and Framework)
sharepointdatabasesql-serversysadmintutorial
3 Posts 2 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.
  • B Offline
    B Offline
    balaji t
    wrote on last edited by
    #1

    hi folks, A SP in sql server is not returning a string variable as output variable ..can any1 let me know how to return a string variable from SP in sql server?A function returns a string variable whereas a SP doesnt return.y? for e.g I have created a SP create procedure SP_abc( @a INT @b out VARCHAR(10) ) as begin set @b = 'ABCD' end How to get the value of b in the front end?

    T.Balaji

    J 1 Reply Last reply
    0
    • B balaji t

      hi folks, A SP in sql server is not returning a string variable as output variable ..can any1 let me know how to return a string variable from SP in sql server?A function returns a string variable whereas a SP doesnt return.y? for e.g I have created a SP create procedure SP_abc( @a INT @b out VARCHAR(10) ) as begin set @b = 'ABCD' end How to get the value of b in the front end?

      T.Balaji

      J Offline
      J Offline
      Jaime Olivares
      wrote on last edited by
      #2

      If you fire the SP with SqlCommand.ExecuteNonQuery(), then you can retrieve the parameter with SqlCommand.Parameters collection as:

      SqlCommand command = new SqlCommand("SP_abc");
      command.CommandType = CommandType.StoredProcedure;
      command.Parameters.Add("@a", SqlDbType.Int);
      command.Parameters["@a"].Value = somevaluehere;
      command.ExecuteNonQuery()
      string b = (string)command.Parameters["@b"];

      Best regards, Jaime.

      B 1 Reply Last reply
      0
      • J Jaime Olivares

        If you fire the SP with SqlCommand.ExecuteNonQuery(), then you can retrieve the parameter with SqlCommand.Parameters collection as:

        SqlCommand command = new SqlCommand("SP_abc");
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@a", SqlDbType.Int);
        command.Parameters["@a"].Value = somevaluehere;
        command.ExecuteNonQuery()
        string b = (string)command.Parameters["@b"];

        Best regards, Jaime.

        B Offline
        B Offline
        balaji t
        wrote on last edited by
        #3

        hi, But im getting a value as 1 and 0 and im not getting the value of though im usign LINQ.Can u tell me whether it is possible to return a string value as output in the front end using SP?

        T.Balaji

        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