复制代码 代码如下:
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>");
标签:
文本格式数据,数据库

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com