How 2 return a string value from sql server in SP?
-
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
-
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
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.
-
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.