Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I have written a code to extract data from different text files. I am reading only 3 values from all the different text files. Now i want to write them in database table.

please tell me how to do that through c# coding???




C#
private void button1_Click(object sender, EventArgs e)
    {
        string to_date = dateTimePicker2.Value.ToString("yyyy/MM/dd");
        Console.WriteLine("a");
       string[] name = new string[18] {"005","006","008","015","017","019","024","032","034","035","037","038","039","041","049","050","051","014"};

        for (int i = 0; i < name.Length; i++)
          {   conairdata(to_date, name[i]);   }
            label9.Text = " Completed";
            label9.Refresh();
            Console.WriteLine("d");
    }

    public void conairdata(string to_date , string name)
    {
        Console.WriteLine("e");
        string path = "H:\\Su\\air\\reporting\\mdata"+name+".rpt";
        // nofcol and nofrows of our tile array
        int nofcol = 0;
        int nofrows = File.ReadLines(path).Count();
        StreamReader sReader = new StreamReader(path);
        string line = sReader.ReadLine();
        string[] tileNo = line.Split(',');
        nofcol = tileNo.Count();
        // Set Minimum to 1 to represent the first file being copied.
        progressBar1.Minimum = 1;
        // Set Maximum to the total number of Users created.
        progressBar1.Maximum = nofrows;
        // Set the initial value of the ProgressBar.
        progressBar1.Value = 1;
        // Set the Step property to a value of 1 to represent each user is being created.
        progressBar1.Step = 1;
        sReader.Close();
        Console.WriteLine("f");
        // Re-initialising sReader
        sReader = new StreamReader(path);
        DateTime datum, dt1,dt2, dt3;
        for (int y = 1; y < nofrows; y++)      // read number of rows
        {
            line = sReader.ReadLine();
            tileNo = line.Split(',');
            string k = tileNo[19];
            string l = tileNo[3];
            string s = tileNo[0];

            try
            {
                string x = s.Substring(s.IndexOf("(") + 1, (s.IndexOf(")") - s.IndexOf("(") - 1)).Replace(".", "-");
                 datum = Convert.ToDateTime(x);      // convert extracted date to DateTime format

             dt1 = DateTime.Parse(Convert.ToString(datum));

             logger(dt1, l, k);
            } 
            catch(Exception)
            {   }
       if (y != nofrows)
            {    progressBar1.PerformStep();    }
        } 
        label9.Text = " Now processing... Please wait";
            label9.Refresh();
            sReader.Close();
    }
Posted

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