I execute a stored procedure from C# like this:
medianOfProjects = db.ExeSQLParamByDateTime("usp_TaskStatistics_Median_Calculation", parameters, "@TaskTypeTableType", 1, startDate, endDate
unitNumberFrom, unitNumberTo, unitNumberBldgsSegsFrom, unitNumberBldgsSegsTo, unitNumberSqrFrom, unitNumberSqrTo, unitNumberWoodStoriesFrom,
unitNumberWoodStoriesTo, currentRegionKey);
ExeSQLParamByDateTime method is too large:
public DataTable ExeSQLParamByDateTime(string sprocName, DataTable paramArray, string tableTypeName, int LegacyKey, DateTime startingDate, DateTime endingDate,
int unitNumberFrom, int unitNumberTo, int BldgSegsFrom, int BldgSegsFromTo, int SquareFootageFrom, int SquareFootageTo, int WoodStoriesFrom,
int WoodStoriesTo, int StatusKey)
{
SqlCommand cmd = new SqlCommand(sprocName, this.dbconn);
var startDate = startingDate.Date;
var endDate = endingDate.Date;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter(tableTypeName, SqlDbType.Structured));
cmd.Parameters[tableTypeName].Value = paramArray;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@LegacyKey", SqlDbType.Int));
cmd.Parameters["@LegacyKey"].Value = LegacyKey;
cmd.Parameters.Add(new SqlParameter("@StartingDate", SqlDbType.DateTime));
cmd.Parameters["@StartingDate"].Value = startDate;
cmd.Parameters.Add(new SqlParameter("@EndingDate", SqlDbType.DateTime));
cmd.Parameters["@EndingDate"].Value = endDate;
cmd.Parameters.Add(new SqlParameter("@UnitNumberFrom", SqlDbType.Int));
cmd.Parameters["@UnitNumberFrom"].Value = unitNumberFrom;
cmd.Parameters.Add(new SqlParameter("@UnitNumberTo", SqlDbType.Int));
cmd.Parameters["@UnitNumberTo"].Value = unitNumberTo;
//etc
//etc
}
There is no way to optimize this? I just checking for good practices, as you can see I send param DataTable to execute sql TableType and in addition send parameters, but I don't found anything similar like this. Help is appreciated. regards