我现在从不同的文本文件中读取数据如何在数据库表中写入? [英] I have Read data from different text files now how to write it in a database table?
本文介绍了我现在从不同的文本文件中读取数据如何在数据库表中写入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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???
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();
}
推荐答案
这篇关于我现在从不同的文本文件中读取数据如何在数据库表中写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文