当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net下降文本格式数据导入到数据库中的代码

asp.net下降文本格式数据导入到数据库中的代码

2017年12月12日  | 移动技术网IT编程  | 我要评论

四川省地方税务局网上申报,长沙教育学院,模式识别

复制代码 代码如下:

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>");

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网