Hey,
Well based on Gary example I've build this code:
now some questions if i may:Code:protected void Page_Load(object sender, EventArgs e) { List<DataCollection> mycollection = GetData(); foreach(DataCollection dc in mycollection) { Trace.Warn(dc.id.ToString()); Trace.Warn(dc.loginName); } } public List<DataCollection> GetData() { using (SqlConnection connection = new SqlConnection(GetConnectionString())) { using (SqlCommand command = new SqlCommand("SELECT id,login_name FROM users_details",connection )) { connection.Open(); return CollectData(command.ExecuteReader()); } } } public List<DataCollection> CollectData(SqlDataReader reader) { List<DataCollection> dataCollection = new List<DataCollection>(); while (reader.Read()) { DataCollection myClass = new DataCollection(); myClass.id = (int)reader[0]; myClass.loginName = (string)reader[1]; dataCollection.Add(myClass); } return dataCollection; }
A) is this a good practice of pulling data?
B) though i fully understand how this code works, i don't understand why using this method is better practice then returning datasets or arraylist for example?
C) should i always pull data this way and this is mean i should build a custom class for every query i have ?
thanks.




If you Like it 
Reply With Quote