2
我通過c#讀取文件,文件格式是這樣的。
輸入文件將文本文件保存到mysql數據庫中c#
00001740, 0.125, 0, able
00001740, 0.125, 0, unable
00002098, 0, 0.75, country
00002312, 0, 0, love
我想在MySQL數據庫文件。我編寫的代碼將每行存儲在數據庫的每個行中。但下面的代碼只寫文本文件的第一行
private void button1_Click(object sender, EventArgs e)
{
string MyConString = "server=localhost;" +
"database=zahid;" + "password=zia;" +
"User Id=root;";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
connection.Open();
StreamReader reader = new StreamReader("D:\\out.txt");
string line;
while ((line = reader.ReadLine()) != null)
{
string[] parts = line.Split(',');
command.CommandText = "insert into score(POS_ID,Pos,Neg,Word) values('" + parts[1] + "','" + parts[2] + "','" + parts[3] + "','" + parts[4] + "')";
Reader = command.ExecuteReader();
}
}
這個代碼僅返回第一線,但我想,在數據庫中的文本文件存儲的所有行。在此先感謝