问题
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