title: for a single click it has to read a text file till the end of text in c#
body: <p>i'm reading a text file and storing it to a data base.For a single click i'm able to read a single line from text file and it can be stored to a database.</p>
  
  <p>But my text file is huge,so i need a method so that a single click will start reading the file and it can be stored to a database till the end of file.</p>
  
  <p>this is my code:</p>
  
  <pre><code>Program problem = new Program();
  SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=Billing;Integrated Security=True");
  SqlCommand cmd = new SqlCommand();
  
  
  
  string line = "";
  string billno = null;
  string billdate = null;
  string hosp_no = null;
  string ip_no = null;
  string name = null;
  string test = null;
  string ward = null;
  string rad = null;
  string pathNames = "C:\\Users\\Administrator\\Desktop\\Ex_1\\KHL.txt";
  
  ArrayList rawData = new ArrayList();
  
   try
  {
  
      StreamReader readFile = new StreamReader(pathNames);
  
      do
      {
          //tim
  
          if ((line = readFile.ReadLine()) != null)
          {
              //  Console.WriteLine(line);
              if (line.Contains("RADIOLOGY"))
              {
                  rawData.Add(line);
                  //Console.ReadKey();
              }
  
          }
          else
          {
              line = null;
          }
      } while (line != null);
  
  
      int rIn = rawData.Count;
  
      for (int i = 0; i &lt; rIn; i++)
      {
          con.Open();
  
          string[] data = (rawData[i] + "").Split('~');
          string da = "";
          hosp_no = data[1].Substring(data[1].Length - 8, 8);
          ip_no = data[2].Substring(data[1].Length - 7, 7);
          name = data[8].Replace("'", "''");
          billno = data[3];
          billdate = data[4].Substring(5, 2) + "/" + data[4].Substring(8, 2) + "/" + data[4].Substring(0, 4);
          test = data[5];
          ward = data[16];
  
          if (data.Length == 1 &amp;&amp; data[0] == "") da = "Finish";
          else
          {
  
  
              cmd = new SqlCommand("insert into ex_1 values('" + hosp_no + "','" + ip_no + "','" + name.Replace(" ' ", " '' ") + "','" + billno + "','" + billdate + "','" + ward + "','" + test + "')", con);
              cmd.Parameters.AddWithValue("@name", name);
              cmd.ExecuteNonQuery();
              con.Close();
              Console.Read();
  
          }
          //Console.WriteLine(da);
          Console.Read();
      }
  }
  catch (Exception f)
  {
      Console.WriteLine(f.Message);
      Console.Read();
  }
  </code></pre>