Using our Stored Procedures

Coordinator
Feb 25, 2008 at 6:03 PM
Edited Feb 25, 2008 at 6:24 PM
Lets execute the procedure spExecuteProcedure like that:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE spExecuteProcedure
@param1 int,
@param2 varchar(50),
@param3 smalldatetime
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO T_TEST (field1,field2 ,field3)
VALUES(@param1 ,@param2 ,@param3)
END
GO

public void ExecuteProcedures(int param1, string param2, DateTime param3) {

//declare a Paulovich Command object
Command command = new Command();

try {

//define a CommandType on Enumerator
command.CommandType = CommandType.StoredProcedure;

//add values to object
command.AddWithValue("param1", param1);
command.AddWithValue("param2", param2);
command.AddWithValue("param3", param3);

//execute the procedure easily
command.ExecuteNonQuery("spExecuteProcedure");

} catch (Exception) {
throw;
}

}