开发者

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

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


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.


Use an index for your where clause and a SqlConnection.


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜