c# - How to increase speed in sql string when insert to ms access datebase -


i have text file, size 3mb(15,000 strings), inserted text file. processing takes 30 minutes. how can increase speed of ms access database.and want progress bar, if it's processing long.

        openfiledialog ofd = new openfiledialog();                  if (ofd.showdialog() == dialogresult.ok)         {                             filestream fs = file.openread(ofd.filename);             bufferedstream bs = new bufferedstream(fs);             streamreader sr = new streamreader(bs);             {                 metroprogressbar1.maximum = convert.toint32(sr.length);                 (int = 0; < sr.length; i++)                 {                                             metroprogressbar1.value++;                 }                               string s;                 while ((s = sr.readline()) != null)                 {                                                 try                         {                             string pattern = @"[\d]{1,8}([.,][\d]{1,4})?";                              regex r = new regex(pattern);                             match m = r.match(s.substring(77, 41));                             while (m.success)                             {                                 //console.writeline(m);                                 m = m.nextmatch();                             }                             string[] row1 = {                                          s.substring(46, 31),                                          s.substring(77, 41),                                          s.substring(118, 8),                                          s.substring(127, 10),                                          s.substring(138, 10)                                      };                             metrolistview1.items.add(s.substring(0, 45)).subitems.addrange(row1);                             string cmdstr = "insert ggg (event_id, device_id, parameter_id, parameter_int_id, time_id, clock_id, user_id) values ('" + s.substring(0, 45) + "', '" + s.substring(46, 31) + "', '" + s.substring(77, 41) + "', '" + r.match(s.substring(77, 41)) + "',  '" + s.substring(118, 19) + "', '" + s.substring(118, 8) + "',  '" + s.substring(138, 10) + "')";                             oledbconnection con = new oledbconnection(constr);                             oledbcommand com = new oledbcommand(cmdstr, con);                             try                             {                                 con.open();                                 com.executenonquery();                                 con.close();                             }                             catch (exception ex)                             {                                 console.writeline("error", ex.message);                             }                         }                         catch (exception ex)                         {                             messagebox.show("Содержимое файла не соответствует формату таблицы");                         }                 }                 sr.close();             }         }     } 

use single connection db operations. in code snippet opening oledbconnection con = new oledbconnection(constr); each line in file.

it should like:

oledbconnection con = new oledbconnection(constr); while ((s = sr.readline()) != null) {   // job here } con.close(); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -