What is the fastest way to find data in SQLCE in Windows Mobile (using C#)?

China☆狼群 提交于 2019-12-13 08:59:52

问题


What is the fastest way to find data in SQLCE in Windows Mobile (using C#)? I have a database with one million records. Is the fastest way an SQL query, a DataReader, or what?


回答1:


Use an index for your where clause and a SqlConnection.




回答2:


By far the fastest way is to not use the query processor at all. Index the table to the field you want to search on and then use a SqlCeCommand with TableDirect and open a reader. Just adding the query procesor makes it an order of magnitude slower.




回答3:


In my tests the single fastest way is to treat SQLCE like old-style dBase;

// Get a cached Select Command
SqlCeCommand command = this.selectCommand;
// Tell it to match the first value you are searching for (having already set IndexName on the command 
command.SetRange(DbRangeOptions.Match, new object[] { key }, null);
// Read a single row
SqlCeDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.SingleRow);
object value = null;
// Read your value by column index.
for (int i = 1; reader.Read(); i++)
{
    value = reader[1];
}


来源:https://stackoverflow.com/questions/1689455/what-is-the-fastest-way-to-find-data-in-sqlce-in-windows-mobile-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!