public
void
InputData()
{
DataTable dt =
new
DataTable();
string
strFilePath =
"e:\\ouput1.txt"
;
FileStream fs =
new
FileStream(strFilePath, FileMode.Open, FileAccess.Read);
StreamReader sr =
new
StreamReader(fs, System.Text.Encoding.UTF8);
//utf-8格式,下面的是gb2312格式
///StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
//SqlConnection conn = DatabaseConnection.GetConnected();
//conn.Open();
string
strLine0 = sr.ReadLine();
///當(dāng)行內(nèi)需要重新分散元素的是時(shí)候,我注釋掉以下代碼,demo里,用“,”區(qū)分行元素,然后,用ado.net插入數(shù)據(jù)庫(kù)就可以了
/*
String strLine1 = sr.ReadLine();
String strLine2 = sr.ReadLine();*/
while
(strLine0 !=
null
)
{
string
[] strArray =
new
string
[4];
strArray = strLine0.Split(
','
);
DataRow dr = dt.NewRow();
dr[0] = strArray[0];
dr[1] = strArray[1];
dr[2] = strArray[2];
dr[3] = strArray[3];
//string sql = "insert into 你的表名 values('" + dr[0] + "','" + dr[1] + "','" + dr[2] + "','" + dr[3] + "')";
//SqlCommand cmd = new SqlCommand(sql, conn);
//cmd.ExecuteNonQuery();
dt.Rows.Add(dr);
strLine0 = sr.ReadLine();
}
sr.Close();
fs.Close();
//conn.Close();
}