日期:2014-05-17 浏览次数:20977 次
private void ReadData()
{
string sql = "";
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("G:\\TXT");
FileInfo[] ff = di.GetFiles("*.txt"); //只取文本文件
foreach (FileInfo temp in ff)
{
using (StreamReader sr = temp.OpenText())
{
con.Open();
string all1 = sr.ReadToEnd(); //从开始到末尾位置全部读取
string tid = all1.Substring(18, 8);
string tname = all1.Substring(28);
sql = "insert into txttest(t_id,t_name) values('"+tid+"','"+tname+"')";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
}
temp.Delete(); //删除文件
}
}
string sql = "";
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("G:\\TXT");
FileInfo[] ff = di.GetFiles("*.txt"); //只取文本文件
foreach (FileInfo temp in ff)
{
using (StreamReader sr = new StreamReader(temp.FullName, Encoding.GetEncoding("gb2312")))
{
con.Open();
string all1 = sr.ReadToEnd(); //从开始到末尾位置全部读取
string tid = all1.Substring(18, 8);
string tname = all1.Substring(28);
sql = "insert into txttest(t_id,t_name) values('" + tid + "','" + tname + "')";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
}
temp.Delete(); //删除文件
}