C# 如何快速读取数据库中的数据?
**我有9个comboboxentry和9个table Paradox*.db.*表格适用于comboboxentry。这是35-38秒的工作??需要更快的速度。请帮助。我正在尝试使用阵列,但这是个坏主意,时间增加了C# 如何快速读取数据库中的数据?,c#,database,combobox,backgroundworker,C#,Database,Combobox,Backgroundworker,**我有9个comboboxentry和9个table Paradox*.db.*表格适用于comboboxentry。这是35-38秒的工作??需要更快的速度。请帮助。我正在尝试使用阵列,但这是个坏主意,时间增加了 *_connection.Open (); cmdComboboxTable1=new OleDbCommand("SELECT DISTINCT cell FROM Table1 ;",_connection); OleDbDat
*_connection.Open ();
cmdComboboxTable1=new OleDbCommand("SELECT DISTINCT cell FROM Table1 ;",_connection);
OleDbDataAdapter adapComboboxTable1=new OleDbDataAdapter(cmdComboboxTable1);2500records
cmdComboboxTable2=new OleDbCommand("select DISTINCT cell from table2 where cell is not null;",_connection);79000Records
OleDbDataAdapter adapComboboxTable2=new OleDbDataAdapter(cmdComboboxTable2);
cmdComboboxTable3=new OleDbCommand("select distinct cell from table3 WHERE EUR_STK_CD IS NOT NULL;",_connection);80000records
OleDbDataAdapter adapComboboxTable4=new OleDbDataAdapter(cmdComboboxTable4);9records
cmdComboboxTable4=new OleDbCommand("select cell1,cell2 FROM Table4;",_connection);
OleDbDataAdapter adapComboboxTable4=new OleDbDataAdapter(cmdComboboxTable4);
cmdComboboxTable5=new OleDbCommand("select DISTINCT cell From Table5 ORDER BY cell;",_connection);100000records
OleDbDataAdapter adapComboboxTable5=new OleDbDataAdapter(cmdComboboxTable5);
cmdComboboxTable6=new OleDbCommand("select distinct cell From Table6 where MODL_NM IS NOT NULL;",_connection);60000records
OleDbDataAdapter adapComboboxTable6=new OleDbDataAdapter(cmdComboboxTable6);
cmdComboboxtable7=new OleDbCommand("select distinct cell From table7 where cell IS NOT NULL;",_connection);120 records
OleDbDataAdapter adapComboboxTable=new OleDbDataAdapter(cmdComboboxTable7);12records
cmdComboboxTable8=new OleDbCommand("select cell FROM Table8;",_connection);
OleDbDataAdapter adapComboboxTable8=new OleDbDataAdapter(cmdComboboxTable8);
cmdComboboxTable9=new OleDbCommand("select distinct Cell1,cell2 FROM Table9;",_connection);11records
OleDbDataAdapter adapComboboxTable9=new OleDbDataAdapter(cmdComboboxTable9);
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
//StartBackgroundworker();
bgComboboxTable9.RunWorkerAsync();
bgComboboxTable2.RunWorkerAsync();
bgComboboxTable3.RunWorkerAsync();
bgComboboxTable4.RunWorkerAsync();
bgComboboxTable5.RunWorkerAsync();
bgComboboxTable6.RunWorkerAsync();
bgComboboxTable7.RunWorkerAsync();
bgComboboxTable8.RunWorkerAsync();
//This is method in all backgrounder worker
drComboboxTable9 = cmdComboboxTable9.ExecuteReader ();
ListStore Table1List;
string Table1String;
Table9List=new ListStore(typeof(string));
comboboxentry4.Model=Table1List;
while(drComboboxTable1.Read()){
Table9String=(string)drComboboxTable1["LONG_NM"];
Table9List.AppendValues(Table1String);
}
//method end
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);*
把索引放在表格上,这样where子句和dinstinct子句都能有效地工作 即: 表1和表2上的单元格 表3中的单元格和EUR_STK_CD 表5的单元格 表6中的电池和模块 表7的单元格 表9中的单元格1和单元格2 大概我可以补充一下 如果没有必要,不要使用distinct。这会影响性能。 检查索引,在适用的情况下添加索引。检查执行计划并作出决定。 更重要的是,删除所有未使用的索引。
删除未使用的索引不只是在插入和更新时才有帮助吗?我在应用程序搜索中是这样做的。所有记录都有不同ID的副本,以便在另一个大表中搜索所需的记录。谢谢你的回答。好的,我会试试。谢谢你的回答。