{
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();
}
6 个解决方案
#1
试试:
StreamReader streamReader = new StreamReader(fileStrem,System.Text.Encoding.GetEncoding("gb2312"));
System.Text.Encoding.GetEncoding("gb2312") 这句用你自己的文件编码改一下
http://www.webdiyer.com
StreamReader streamReader = new StreamReader(fileStrem,System.Text.Encoding.GetEncoding("gb2312"));
System.Text.Encoding.GetEncoding("gb2312") 这句用你自己的文件编码改一下
http://www.webdiyer.com
#2
另存txt文件,编码选择UTF-8试试
#3
谢谢大家。非常感谢
#4
编码换一下就行了
#5
编码格式转换一下!
#6
编码选择UTF-8,另存为,选择编码,就可以了
#1
试试:
StreamReader streamReader = new StreamReader(fileStrem,System.Text.Encoding.GetEncoding("gb2312"));
System.Text.Encoding.GetEncoding("gb2312") 这句用你自己的文件编码改一下
http://www.webdiyer.com
StreamReader streamReader = new StreamReader(fileStrem,System.Text.Encoding.GetEncoding("gb2312"));
System.Text.Encoding.GetEncoding("gb2312") 这句用你自己的文件编码改一下
http://www.webdiyer.com
#2
另存txt文件,编码选择UTF-8试试
#3
谢谢大家。非常感谢
#4
编码换一下就行了
#5
编码格式转换一下!
#6
编码选择UTF-8,另存为,选择编码,就可以了