我如何快速读取数据库中的数据?

时间:2014-09-09 15:11:50

标签: c# database combobox backgroundworker

**我有9个comboboxentry和9个表Paradox * .db。**表适用于comboboxentry。这是工作35-38秒?需要更快。请帮助。我正在尝试使用数组,但这是个坏主意时间增加。

 *_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);*

2 个答案:

答案 0 :(得分:1)

我大概可以补充一下,

  • 如果没有必要,请不要使用。这会扼杀表现。
  • 检查索引,在适用的地方添加索引。检查执行计划并决定。
  • 更重要的是,删除所有未使用的索引。

答案 1 :(得分:0)

在表上放置索引,以便where子句有效地工作,dinstinct子句也可以。

即:

    celltable1
  • table2cell
  • EUR_STK_CDtable3
  • cell table5
  • cell
  • MODL_NMtable6
  • cell table7
  • cell1
  • cell2table9