asp.net下降文本格式数据导入到数据库中的代码
更新时间:2010年05月14日 16:54:37 作者:
导入文本格式数据到数据库中的代码,需要的朋友可以参考下。
复制代码 代码如下:
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>");
相关文章
实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上
一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个Item时,让Item有特效显示,离开时,恢复原样有演示动画,感兴趣的朋友可以了解下啊2013-01-01asp.net ASPxTextBox等控件实现"回车模拟Tab"的 常用代码整理
今天我要实现一些编辑框如ASPxTextBox、ASPxComboBox等控件回车模拟Tab的功能。这没办法,用户用惯了回车,讨厌按Tab来移动焦点(鼠标点击更麻烦)。2010-03-03ASP.NET中使用Application对象实现简单在线人数统计功能
这篇文章主要介绍了ASP.NET中使用Application对象实现简单在线人数统计功能,本文给出实现步骤和相应代码实例,需要的朋友可以参考下2015-06-06
最新评论