简体   繁体   中英

DataAdapter.Fill too slow

I know DataAdapters have performance issues, but are there any ways around it that might be faster? At the moment, the DataAdapter.Fill method is taking 5-6 seconds on 3000 records, which is too slow for my app. If I remove the Fill line and just execute the SQL (using SQLCE), it takes 20 milliseconds, so I'm guessing the query isn't the problem. I've tried adding BeginLoadData on the datatable, but it makes no difference to the performance.

 using (SqlCeConnection con = new SqlCeConnection(conString))
 {
       con.Open();
       using (SqlCeDataAdapter dAdapter= new SqlCeDataAdapter())
       {

          using (SqlCeCommand com = new SqlCeCommand(query, con))
          {
               com.Parameters.Add("uname", textBox1.Text);
               dAdapter.SelectCommand = com;
               dAdapter.SelectCommand.Connection = con;

               DataTable dTable = new DataTable();


               dAdapter.Fill(dTable);

               dataGridView1.DataSource = dTable;


           }
       }
  }

Are there better ways to fill a DataGridView or speed up the Fill method?

您可以改为将DataGridView绑定到DataReader ,但这可能不会好得多,因为将3000行加载到DataGridView中并不是很方便。

the core problem is loading 3000 for the user at once. no matter how to load 300 records the amount of data is the problem. implement paging within the sql query to allow the user to view a subset of records. the user can then navigate to more records when they need to.

Use BatchUpdate/BatchInsert. Make sure you specify UpdateBatchSize = 3000 (number of records you have)

Here is an example on how to do it: BatchInsert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM