Why is DataTable faster than DataReader

前端 未结 4 1641
轻奢々
轻奢々 2020-11-30 06:12

So we have had a heated debate at work as to which DataAccess route to take: DataTable or DataReader.

DISCLAIMER I am on the DataReader side and the

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 06:28

    I don't think it will account for all the difference, but try something like this to eliminate some of the extra variables and function calls:

    using (SqlDataReader reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            artifactList.Add(new ArtifactString
            {
                FormNumber = reader["FormNumber"].ToString(),
                //etc
            });
         }
    }
    

提交回复
热议问题