FillPosts Method

Topics: Business Logic Layer
Sep 29, 2007 at 11:13 PM
Hi,

In the FillPosts method below why do we require a DataTable to be filled when we can simply fill the post object collection using a DataReader.
Also, since SqlDataAdapter is being used there is no need to open and close the connections. This will be performed automatically.

public override List<Post> FillPosts()
{
List<Post> posts = new List<Post>();

OpenConnection();

string sqlQuery = "SELECT PostID FROM be_Posts ";
SqlDataAdapter sa = new SqlDataAdapter(sqlQuery, providerConn);
DataTable dtPosts = new DataTable();
sa.Fill(dtPosts);

foreach (DataRow dr in dtPosts.Rows)
{
posts.Add(Post.Load(new Guid(dr0.ToString())));
}

providerConn.Close();

posts.Sort();
return posts;
}