SQLCommandGeneral(Data)

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ProjectHistoryCollector.DataAccess
{
public class SQLCommandGeneral
{
void New()
{
}
string ReturnValueParameterName = "RETURN_VALUE";
public SqlCommand GenerateCommand(SqlConnection Connection, MethodInfo Method, Object[] Values)
{
SqlCommand command = new SqlCommand();
command.Connection = Connection;
command.CommandText = Method.Name;
command.CommandType = CommandType.StoredProcedure;
ParameterInfo[] methodParameters = Method.GetParameters();
int index = 0;
foreach (ParameterInfo paramInfo in methodParameters)
{
SqlParameter sqlParameter = new SqlParameter();
sqlParameter.ParameterName = paramInfo.Name;
sqlParameter.ParameterName = "@" + sqlParameter.ParameterName;
sqlParameter.Value = Values[index];
command.Parameters.Add(sqlParameter);
index++;
}
command.Parameters.Add(ReturnValueParameterName, SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
return command;
}
}
}

Resource