Hi,
print 'text statement' in SQL is not considered as an output parameter, it's like as Console.Write('Text') in .NET development environment.
So, please change your sp:
ALTER proc [dbo].[sp_insert]
(
@eid int,
@ename nvarchar(50),
@image nvarchar(50),
@outString nvarchar(100) output
)
as begin
insert into tab (eid , ename , image )
values(
@eid,
@ename,
@image
)
SET @outString = 'Records are inserted successfully'
end
In aspx:
public void InsertSP()
{
SqlConnection cnn = new SqlConnection("your connection string here");
try
{
SqlCommand cmd = new SqlCommand("sp_insert", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@eid", SqlDbType.Int);
cmd.Parameters.Add("@ename", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@image", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@outString", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Output;
cnn.Open();
cmd.ExecuteNonQuery();
LblResult.Visible = true;
LblResult.Text = cmd.Parameters["@outString"].Value.ToString();
}
catch (Exception ex)
{
}
finally
{
if (cnn != null && cnn.State == ConnectionState.Open)
{
cnn.Close();
}
}
}