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>();
try
{
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();
d.date = arr[0];
d.time = arr[1];
d.lat = Convert.ToDouble(arr[3]);
d.lon = Convert.ToDouble(arr[4]);
if (arr[6] == "")
{
d.depth = arr[7];
}
else
{
d.depth = arr[6];
}
if (arr[8] == "")
{
d.mag = arr[9];
}
else
{
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();
cn.Open();
cmd.Connection = cn;
cmd.CommandText = "insert into Nass values(@DateTime,@Latitude,@Longitude,@Depth,@Magnitude)";
cmd.Parameters.AddWithValue("@DateTime",d.date +" "+d.time);
cmd.Parameters.AddWithValue("@Latitude",d.lat);
cmd.Parameters.AddWithValue("@Longitude",d.lon);
cmd.Parameters.AddWithValue("@Depth",d.depth);
cmd.Parameters.AddWithValue("@Magnitude",d.mag);
try
{
cmd.ExecuteNonQuery();
cn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
cn.Close();
}
finally
{
cn.Close();
}
plzz help..