1

I have to display data from multiple SQLite db files (200 approx) in a grid.

I am running a loop for the number of db files in the directory and for each of the file open() connection, get the data, add it in a new grid row and then close the connection.

Now for 200 files I am having to open and close 200 SQLite connections. Obviously, this is making my web page containing the grid respond too slowly and almost takes 2 mins to load the page.

Is there a way to read thru all these files in a faster way?

Here is the code I have:

FileInfo[] dbFiles1 = dbDir.GetFiles("*.db");

int fileCount = dbFiles1.Count();

DataTable dtable = new DataTable();

dtable.Columns.Add("file_name", typeof(string));

dtable.Columns.Add("TIME (Central)", typeof(string));

for (int i = 0; i < fileCount; i++)

{

DataTable dTab = new DataTable();

SQLiteCommand sql_cmd;

SQLiteDataAdapter sql_Da;

DataSet dSet = new DataSet();

SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();

builder.FailIfMissing = true;

builder.DataSource = dirPath + "\\" + dirName + "\\" + reportName;

SQLiteConnection sql_con = new SQLiteConnection(builder.ConnectionString);

sql_con.Open();


sql_cmd = sql_con.CreateCommand();

string commandText = "Select.........";

sql_Da = new SQLiteDataAdapter(commandText, sql_con);

dSet.Reset();

sql_Da.Fill(dSet);

dTab = dSet.Tables[0];

sql_con.Close();

DataTable dtable = new DataTable();

dtable.ImportRow(dTab.Rows[0]);

}

GridView.DataSource = dtable;

GridView.DataBind();
kapa
  • 77,694
  • 21
  • 158
  • 175
Pander
  • 11
  • 1
  • Why isn't all the data in the same file? – hugomg Mar 13 '12 at 12:37
  • For each db connection is required. http://stackoverflow.com/questions/2493331/what-is-best-practice-with-sqlite-and-android – Riddhish.Chaudhari Mar 13 '12 at 12:49
  • Though each db file has has same structure and schema, data is unique in each of the files. I have to present the user with all the files and let him select the file he wants to see details for depending on the parameters that I display in this grid. Now these parameters are stored in a table which is why I have to go into each of the file and to pull this data have to make connection.. – Pander Mar 14 '12 at 04:25

0 Answers0