Good Day valluvanl
First change this
Code:
craete procedure [dbo].[sample_procedure]
as
declare @count int
select @count = count(*) from dbo.Q_C_Users
return @count
to this
Code:
craete procedure [dbo].[sample_procedure]
(
@OutResult int OUTPUT
)
as
set @OutResult = (select count(*) from dbo.Q_C_Users)
and your C# code change it to look like this
Code:
public int returnCount()
{
int availableTables=0;
SqlConnection con = ConnectionManager.GetQueensDBConnection();
SqlCommand cmd = new SqlCommand("SAMPLE_PROCEDURE", con);
cmd.CommandType = CommandType.StoredProcedure;
cmdselect.Parameters.Add("@OutResult", SqlDbType.Int, 4);
cmdselect.Parameters["@OutResult"].Direction = ParameterDirection.Output;
try
{
con.Open();
cmd.ExecuteNonQuery();
availableTables =(int) cmdselect.Parameters["@OutResult"].Value;
}
catch (SqlException)
{
throw;
}
finally
{
con.Close();
}
return availableTables;
and the Code will work.
Kind Regards
Vuyiswa Maseko
Bookmarks