Currently I am using SqlCommands to run stored procedures, I will ExecuteReader and run a while .read, assigning each field to an object then adding that object to a list. This has worked fine so far when stored procedures return a few fields, but now I need to return a full database row of 20+ fields. Is there a better way I should be doing this?
Here is an example of how I am currently using the SqlCommand object and populating a class.
private IEnumerable<DigitalQueue> GetUncheckedQueues()
{
var cmd = new SqlCommand
{
CommandTimeout = 30,
CommandText = "sp_StoredProcedureName",
Connection = Main.Con,
CommandType = CommandType.StoredProcedure
};
var sdrQueues = cmd.ExecuteReader();
var uncheckedQueues = new List<DigitalQueue>();
while (sdrQueues.Read())
{
var workingQueue = new DigitalQueue
{
queueId = sdrQueues.GetValue(0).ToString(),
queueStatus = sdrQueues.GetValue(1).ToString()
};
if (!sdrQueues.IsDBNull(2))
{
workingQueue.queueDate = sdrQueues.GetDateTime(2);
}
uncheckedQueues.Add(workingQueue);
}
return uncheckedQueues;
}