Following code sample demonstrated how
to call a stored procedure using entity spaces esUtility class, return output
parameters from it and display those output parameters in a message box.
Simple stored procedure:
SET
ANSI_NULLS ON
GO
SET
QUOTED_IDENTIFIER ON
GO
ALTER
PROCEDURE spTest
@p1 int = 0,
@p2 int = 0 OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @p2 = @p1 * 10000;
END
GO
Simple function in c#:
private
void SPTest()
{
try
{
esUtility es = new
esUtility();
//No need to use @ sign
esParameter p1 = new
esParameter("p1",
25, esParameterDirection.Input, DbType.Int32, 0);
esParameter p2 = new
esParameter("p2",
esParameterDirection.Output, DbType.Int32, 0);
esParameters parameters = new esParameters();
parameters.Add(p1);
parameters.Add(p2);
es.ExecuteNonQuery(EntitySpaces.Interfaces.esQueryType.StoredProcedure,
"spTest", parameters);
MessageBox.Show(p2.Value.ToString());
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
Where is the connection established? Great to know the SP name, but in which database and on which server with which credentials?
ReplyDelete