Click here to Skip to main content
15,610,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am developing an application in c# that extracts data from a text file & inserts those values into the database. the amount of data to be inserted is way too huge(>100000) & while the data is being inserted, the application shows "Not responding"...

my requirements
1) How do i avoid the "Not Responding" Message
2) i want to update the progress bar as the data is inserted into the database, to show the progress

here is the code that i am using to store into the db
string str;
            List<data> gd = new List<data>();
                using (StreamReader sr = new StreamReader("C:\\Windows\\Temp\\op.txt"))
                    string line;
                    while ((line = sr.ReadLine()) != null)
                        string[] arr = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
                        while (sr.Peek() > 0)

                            string[] s = new string[] { " " };
                            char[] c = new char[] { ' ' };
                            str = sr.ReadLine();
                            arr = str.Split(c);

                            data d = new data();
                   = arr[0];
                            d.time = arr[1];
                   = Convert.ToDouble(arr[3]);
                            d.lon = Convert.ToDouble(arr[4]);
                            if (arr[6] == "")
                                d.depth = arr[7];
                                d.depth = arr[6];
                            if (arr[8] == "")
                                d.mag = arr[9];
                                d.mag = arr[8];
                            OleDbConnection cn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "/earthDB.mdb;Persist Security Info=True");
                            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = cn;
            cmd.CommandText = "insert into Nass values(@DateTime,@Latitude,@Longitude,@Depth,@Magnitude)";

            cmd.Parameters.AddWithValue("@DateTime", +" "+d.time);


            catch (Exception ex)

plzz help..
Updated 29-Jul-13 4:05am
Maciej Los 29-Jul-13 10:08am    
Member 8657306 29-Jul-13 10:12am    
dats already been done, now i want to avoid s/w hanging & show the progress bar as the data is inserted
ZurdoDev 29-Jul-13 10:14am    
I believe Application.DoEvents will allow the UI to respond to queued messages so you will want to call that as you are updating your progress bar.
Member 8657306 29-Jul-13 10:16am    
how do i do that?? please help i am new to this kind of development
ZurdoDev 29-Jul-13 10:18am    
Do what exactly?

1 solution

First of all, please, read my comment to the question.

As i had mentioned in my past answer: Storing Array Elements into Access Database in C#[^] - Instead loading text file into array, read this file direct into Access database using JET 4.0. OLEDB drivers. Belive me, it's good advice. It's simplest, it's easiest and...

If you want to show progressbar to show the user that operation is in progress, you need to read about threading. I would suggest you to use recommended method (OLEDB) and Indeterminate progress bars to display animation which is used to show that an operation is ongoing.
Threading Tutorial[^]
Threading (C# Programming Guide)[^]

More about:
Progress Bars[^]
Progress Bars, Threads, Windows Forms, and You[^]
Progress Bar using C#[^]
Show User Progress Of Inserting Records By Using Progressbar[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900