代码如下:if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
FileStream fileStrem = File.OpenRead(openFileDialog1.FileName);
StreamReader streamReader = new StreamReader(fileStrem);
string line = null;
while ((line = streamReader.ReadLine()) != null)
{
string[] strs = line.Split('|');
string name = strs[0];
string password = strs[1];
string str = "server=PC-20120601YRRO\\SQLEXPRESS;database=test;uid=sa;pwd=123";
SqlConnection conn = new SqlConnection(str);
conn.Open();
string sql = "insert into T_test(username,pwd)values(@name,@pwd)";
SqlCommand comm = new SqlCommand(sql,conn);
comm.Parameters.Add(new SqlParameter("name",name));
comm.Parameters.Add(new SqlParameter("pwd", password));
comm.ExecuteNonQuery();
}
{
FileStream fileStrem = File.OpenRead(openFileDialog1.FileName);
StreamReader streamReader = new StreamReader(fileStrem);
string line = null;
while ((line = streamReader.ReadLine()) != null)
{
string[] strs = line.Split('|');
string name = strs[0];
string password = strs[1];
string str = "server=PC-20120601YRRO\\SQLEXPRESS;database=test;uid=sa;pwd=123";
SqlConnection conn = new SqlConnection(str);
conn.Open();
string sql = "insert into T_test(username,pwd)values(@name,@pwd)";
SqlCommand comm = new SqlCommand(sql,conn);
comm.Parameters.Add(new SqlParameter("name",name));
comm.Parameters.Add(new SqlParameter("pwd", password));
comm.ExecuteNonQuery();
}
解决方案 »
- C#没有Button1.Attribute("onclick")这种属性吗?
- asp.net程序提取权限问题
- 从C# Windows 开发 转 ASP.NET 开发,请推荐一些书或资料。
- 回发或回调参数无效问题``急急``高手解决一下啊
- 如何得到DATAGRID中指定值的哪一行的行号?比如得到ID=“20050202001”这一行所在行的行号,如果不用循环的话?
- 请大家来看看这个问题怎么解决!:?
- 高手帮忙啊,关于.net+Ext2.0的问题,特急~~
- 帮帮,很急啊
- 如何在客户段控制下拉列表框的可用性
- sql语句错误!
- 如何不通过数据库来修改静态页面显示的图片和文字??
- js能否禁止网页编辑?
StreamReader streamReader = new StreamReader(fileStrem,System.Text.Encoding.GetEncoding("gb2312"));System.Text.Encoding.GetEncoding("gb2312") 这句用你自己的文件编码改一下http://www.webdiyer.com