public static int YourFunction1(int param1, int param2)
{
SqlParameter[] objParameter = new SqlParameter[2];
objParameter[0] = new SqlParameter("@param1", param1);
objParameter[1] = new SqlParameter("@param2", param2);
return ExecuteNonQuery("YourProcedureName", objParameter);
}
Code (C#)
public static int ExecuteNonQuery(string procedureName, SqlParameter[] parameters)
{
SqlConnection oConnection = new SqlConnection(AccessConfig.GetConnectionString());
SqlCommand oCommand = new SqlCommand(procedureName, oConnection);
oCommand.CommandType = CommandType.StoredProcedure;
int iReturnValue;
oConnection.Open();
using (SqlTransaction oTransaction = oConnection.BeginTransaction())
{
try
{
if (parameters != null)
oCommand.Parameters.AddRange(parameters);
oCommand.Transaction = oTransaction;
iReturnValue = oCommand.ExecuteNonQuery();
oTransaction.Commit();
}
catch
{
oTransaction.Rollback();
throw;
}
finally
{
if (oConnection.State == ConnectionState.Open)
oConnection.Close();
oConnection.Dispose();
oCommand.Dispose();
}
}
return iReturnValue;
}
Tag : .NET, Win (Windows App), C#, VS 2008 (.NET 3.x)