asp.net下降文本格式數據導入到數據庫中的代碼
來源:懂視網
責編:小采
時間:2020-11-27 22:43:13
asp.net下降文本格式數據導入到數據庫中的代碼
asp.net下降文本格式數據導入到數據庫中的代碼: 代碼如下:StreamReader sr = new StreamReader(E:\\123.txt);//文件路徑 string oneLine; while ((oneLine = sr.ReadLine()) != null) { string[] str = oneLine.Split('|'); string sql = inse
導讀asp.net下降文本格式數據導入到數據庫中的代碼: 代碼如下:StreamReader sr = new StreamReader(E:\\123.txt);//文件路徑 string oneLine; while ((oneLine = sr.ReadLine()) != null) { string[] str = oneLine.Split('|'); string sql = inse

代碼如下:
StreamReader sr = new StreamReader("E:\\123.txt");//文件路徑
string oneLine;
while ((oneLine = sr.ReadLine()) != null)
{
string[] str = oneLine.Split('|');
string sql = "insert into TableDX(number,name,produce,xinghao) values('" + str[0].ToString() + "','" + str[1].ToString().Replace("'","'") + "','" + str[2].ToString() + "','" + str[3].ToString() + "')";
string strConn = "Data Source=.;Initial Catalog=master;User ID=sa;Password=sa";//連接字符串
SqlConnection conn = new SqlConnection(strConn);
int res = 0;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
res = cmd.ExecuteNonQuery();
conn.Close();
}
sr.Close();
this.Response.Write("<script>alert('導入成功');</script>");
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
asp.net下降文本格式數據導入到數據庫中的代碼
asp.net下降文本格式數據導入到數據庫中的代碼: 代碼如下:StreamReader sr = new StreamReader(E:\\123.txt);//文件路徑 string oneLine; while ((oneLine = sr.ReadLine()) != null) { string[] str = oneLine.Split('|'); string sql = inse