Aqui te dejo un ejemplo super simple...
Código:
public object EjecutarInstruccion(SqlConnection mSqlCnn, string TipoEjecucion, string NombreProcedimientoAlmacenado, SqlParameter[] Parametros)
{
SqlCommand sqlCmd;
object oResultado = null;
sqlCmd = new SqlCommand();
try
{
if ((mSqlCnn != null) && mSqlCnn.State != ConnectionState.Open)
{
mSqlCnn.Open();
}
sqlCmd.CommandText = NombreProcedimientoAlmacenado;
sqlCmd.Connection = mSqlCnn;
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddRange(Parametros);
if ((mSqlTran != null))
{
sqlCmd.Transaction = mSqlTran;
}
switch (TipoEjecucion)
{
case "NonQuery":
oResultado = sqlCmd.ExecuteNonQuery();
break;
case "Scalar":
oResultado = sqlCmd.ExecuteScalar();
break;
}
return oResultado;
}
catch (Exception ex)
{
throw new Exception(ex);
}
finally
{
if (mSqlTran == null)
{
if ((mSqlCnn != null) & mSqlCnn.State == ConnectionState.Open)
{
mSqlCnn.Close();
}
}
if ((sqlCmd != null))
{
sqlCmd.Dispose();
}
}
}
Esta facilito, nomas mandale lo que te pide y listo..!