मैं भी इस में देखा, और SqlDataReader.Load funcitons साथ SqlDataAdaptor.Fill विधि तुलना करने के बाद, मुझे लगता है कि SqlDataAdaptor पाया है।भरें विधि दो बार के रूप परिणाम सेट मैं
प्रयुक्त कोड का उपयोग कर के साथ तेजी से कहीं अधिक है:
[TestMethod]
public void SQLCommandVsAddaptor()
{
long adaptorFillLargeTableTime, readerLoadLargeTableTime, adaptorFillMediumTableTime, readerLoadMediumTableTime, adaptorFillSmallTableTime, readerLoadSmallTableTime, adaptorFillTinyTableTime, readerLoadTinyTableTime;
string LargeTableToFill = "select top 10000 * from FooBar";
string MediumTableToFill = "select top 1000 * from FooBar";
string SmallTableToFill = "select top 100 * from FooBar";
string TinyTableToFill = "select top 10 * from FooBar";
using (SqlConnection sconn = new SqlConnection("Data Source=.;initial catalog=Foo;persist security info=True; user id=bar;password=foobar;"))
{
// large data set measurements
adaptorFillLargeTableTime = MeasureExecutionTimeMethod(sconn, LargeTableToFill, ExecuteDataAdapterFillStep);
readerLoadLargeTableTime = MeasureExecutionTimeMethod(sconn, LargeTableToFill, ExecuteSqlReaderLoadStep);
// medium data set measurements
adaptorFillMediumTableTime = MeasureExecutionTimeMethod(sconn, MediumTableToFill, ExecuteDataAdapterFillStep);
readerLoadMediumTableTime = MeasureExecutionTimeMethod(sconn, MediumTableToFill, ExecuteSqlReaderLoadStep);
// small data set measurements
adaptorFillSmallTableTime = MeasureExecutionTimeMethod(sconn, SmallTableToFill, ExecuteDataAdapterFillStep);
readerLoadSmallTableTime = MeasureExecutionTimeMethod(sconn, SmallTableToFill, ExecuteSqlReaderLoadStep);
// tiny data set measurements
adaptorFillTinyTableTime = MeasureExecutionTimeMethod(sconn, TinyTableToFill, ExecuteDataAdapterFillStep);
readerLoadTinyTableTime = MeasureExecutionTimeMethod(sconn, TinyTableToFill, ExecuteSqlReaderLoadStep);
}
using (StreamWriter writer = new StreamWriter("result_sql_compare.txt"))
{
writer.WriteLine("10000 rows");
writer.WriteLine("Sql Data Adapter 100 times table fill speed 10000 rows: {0} milliseconds", adaptorFillLargeTableTime);
writer.WriteLine("Sql Data Reader 100 times table load speed 10000 rows: {0} milliseconds", readerLoadLargeTableTime);
writer.WriteLine("1000 rows");
writer.WriteLine("Sql Data Adapter 100 times table fill speed 1000 rows: {0} milliseconds", adaptorFillMediumTableTime);
writer.WriteLine("Sql Data Reader 100 times table load speed 1000 rows: {0} milliseconds", readerLoadMediumTableTime);
writer.WriteLine("100 rows");
writer.WriteLine("Sql Data Adapter 100 times table fill speed 100 rows: {0} milliseconds", adaptorFillSmallTableTime);
writer.WriteLine("Sql Data Reader 100 times table load speed 100 rows: {0} milliseconds", readerLoadSmallTableTime);
writer.WriteLine("10 rows");
writer.WriteLine("Sql Data Adapter 100 times table fill speed 10 rows: {0} milliseconds", adaptorFillTinyTableTime);
writer.WriteLine("Sql Data Reader 100 times table load speed 10 rows: {0} milliseconds", readerLoadTinyTableTime);
}
Process.Start("result_sql_compare.txt");
}
private long MeasureExecutionTimeMethod(SqlConnection conn, string query, Action<SqlConnection, string> Method)
{
long time; // know C#
// execute single read step outside measurement time, to warm up cache or whatever
Method(conn, query);
// start timing
time = Environment.TickCount;
for (int i = 0; i < 100; i++)
{
Method(conn, query);
}
// return time in milliseconds
return Environment.TickCount - time;
}
private void ExecuteDataAdapterFillStep(SqlConnection conn, string query)
{
DataTable tab = new DataTable();
conn.Open();
using (SqlDataAdapter comm = new SqlDataAdapter(query, conn))
{
// adaptor fill table function
comm.Fill(tab);
}
conn.Close();
}
private void ExecuteSqlReaderLoadStep(SqlConnection conn, string query)
{
DataTable tab = new DataTable();
conn.Open();
using (SqlCommand comm = new SqlCommand(query, conn))
{
using (SqlDataReader reader = comm.ExecuteReader())
{
// IDataReader Load function
tab.Load(reader);
}
}
conn.Close();
}
परिणाम:
10000 पंक्तियों:
SQL डेटा एडाप्टर 100 बार तालिका 10000 पंक्तियों को भरें: 11782 मिलीसेकंड
एसक्यूएल डेटा रीडर 100 गुना टेबल लोड स्पीड 10000 पंक्तियां: 26047 मिलीसेकंड
1000 पंक्तियां:
SQL डेटा एडाप्टर 100 बार तालिका भरने गति 1000 पंक्तियाँ: 984 मिलीसेकेंड
SQL डेटा रीडर 100 बार तालिका लोड गति 1000 पंक्तियाँ: 2031 मिलीसेकेंड
100 पंक्तियां:
SQL डेटा एडाप्टर 100 बार तालिका भरने गति अधिकतम 100 पंक्तियां: 125 मिलीसेकेंड
SQL डेटा रीडर 100 बार तालिका लोड गति अधिकतम 100 पंक्तियां: 235 मिलीसेकेंड
10 पंक्तियों:
SQL डेटा एडाप्टर 100 बार तालिका भरने की गति 10 पंक्तियों: 32 मिलीसेकंड
SQL डेटा रीडर 100 बार तालिका लोड गति 10 पंक्तियों: 93 मिलीसेकंड
प्रदर्शन समस्याओं के लिए, SqlDataAdaptor.Fill विधि का उपयोग करना अधिक कुशल है। तो जब तक आप पैर के उपयोग में खुद को शूट नहीं करना चाहते हैं। यह छोटे और बड़े डेटा सेट
डुप्लिकेट प्रश्न के लिए तेज़ी से काम करता है: http://stackoverflow.com/questions/4089471/how-do-i-fill-a-datatable-using-datareader – vapcguy