I was just wondering if there is a way to execute a stored procedure with out naming the parameters. Meaning that C# resolves the parameters in the order they're declared within the stored procedure.
public static DataTable GetRelatedResources(string StoredProcedure, object[] Parameters)
{
var Results = new DataTable();
try
{
using (SqlConnection conn = new SqlConnection())
{
using (SqlCommand cmd = new SqlCommand(ConfigurationManager.ConnectionStrings["MK3Entities"].ConnectionString))
{
conn.Open();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = StoredProcedure;
if (Parameters!= null)
{
foreach(var Param in Parameters)
{
// I Want To Do something like this
cmd.Parameters.AddWithValue(Param);
}
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(Results);
}
}
}
catch (Exception ex)
{
MMSLogger.Instance.WriteToLog("Exception Executing Stored Procedure:" + ex.Message);
}
return Results;
}