Which would be quicker.
1) Looping a datareader and creating a custom rows and columns based populated datatable
2) Or creating a dataAdapter object and just (.Fill)ing a datatable.
Does the performance of a datareader still hold true upon dynamic creation of a datatable?
The DataAdapter uses a DataReader under the hood so your experience would likely be the same.
The benefit of the DataAdapter is you cut out a lot of code that would need maintenance.
This debate is a bit of a religious issue so definitely look around and decide what works best for your situation:
Your option #1 would be slower. However, there's a better way to convert a datareader to a datatable than adding custom rows by hand:
DataTable dt = new DataTable();
using (SqlConnection conn = GetOpenSqlConnection())
using (SqlCommand cmd = new SqlCommand("SQL Query here", conn)
using (IDataReader rdr = cmd.ExecuteReader())
{
dt.Load(rdr);
}
I can't comment on the difference between this and using .Fill()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With