c# win form 文本文件中的數據新增到數據庫...求解..............
this.openFileDialogInPut.Filter = "text文檔(txt) |*.txt";if (this.openFileDialogInPut.ShowDialog() == DialogResult.OK)
{
try
{
string filePath = this.openFileDialogInPut.FileName;
if (filePath.LastIndexOf("\\") > -1)
{
filePath = filePath.Substring(filePath.LastIndexOf("\\") + 1);
FileStream fileStream = new FileStream(filePath, FileMode.Open);
byte[] buff = new byte[2048];
while (-1 != fileStream.Read(buff, 0, buff.Length))
{
MessageBox.Show(Encoding.Default.GetString(buff).Length.ToString());
}
}
}
catch (Exception error)
{
// 提示錯誤位置,錯誤原因
MessageBox.Show("錯誤位置:資料匯入\n錯誤原因:" + error.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
怎樣解決啊....上班ing....線上等答案. --------------------编程问答-------------------- up --------------------编程问答-------------------- 什么东西啊 --------------------编程问答-------------------- 帮你找错很难,我给你提供一个解决方案试试
using (StreamReader sr = new StreamReader(txtOpenFile.Text, Encoding.GetEncoding("gb2312")))
{
while (sr.Peek() >= 0)
{
string strLine = sr.ReadLine();
以上代码可得到每行的数据,你可以合并加入你的数组
补充:.NET技术 , C#