Using our Stored Procedures

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 TABLE (field1,field2 ,field3) VALUES(@param1 ,@param2 ,@param3)
END
GO
  1. imports Paulovich.Data;
  2. imports System.Data;
  3. create a method to execute your stored

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;

   }

}

You can implement a transaction too.

Last edited Feb 10, 2009 at 10:25 AM by paulovich, version 8

Comments

No comments yet.