起来还以为是字段属性设置错误,检查一下字段属性弄错了,但是一检查没什么大主题材料:

public static DataTable ExecuteDataTable(string cmdText,
params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
return ExecuteDataTable(conn, cmdText, parameters);
}
}

然后上网搜了一大堆关于数据库中插入文字乱码难点的相干材料;不看幸亏,越看越晕,竟然还也有位老兄说那是mssqlserver的数据爱惜,什么加密字段,靠理念微软也不会那样也不会这样bt,还有些正是数据库字符集的标题,作者试了试得出结论:都以闲聊!

public static object FromDBValue(this object dbValue)
{
return dbValue == DBNull.Value ? null : dbValue;
}
}

调养不奇怪,然而当笔者张开数据表查看导入的多寡时,靠,让人蛋疼的景观爆发了:如下图归于地和卡品音讯全改成不明字符

public static SqlConnection OpenConnection()
{
金沙糖果派对2015cc,SqlConnection conn = new SqlConnection(connstr);
conn.Open();
return conn;
}

金沙糖果派对网站app,private void btninsert_Click(object sender, 伊夫ntArgs e卡塔尔国{if
(odimport.ShowDialog(卡塔尔国 == DialogResult.OK卡塔尔国//思量接过文件;{using
(FileStream filestream = File.OpenRead(odimport.FileName卡塔尔卡塔尔(قطر‎{using
(StreamReader streamreader = new
StreamReader(filestream卡塔尔(قطر‎卡塔尔(قطر‎{//创设连接字符串及树立通道;string connstr =
ConfigurationManager.ConnectionStrings[constr].ConnectionString;using
(SqlConnection conn = new SqlConnection(connstr)){conn.Open();using
(SqlCommand cmd = conn.CreateCommand()){cmd.CommandText = insert into
Phonenumber(Phone,LocalID,LocalAddress,Phonestyle)
values(@Phone,@LocalID,@LocalAddress,@Phonestyle);string line =
null;while ((line = streamreader.ReadLine()) !=
null卡塔尔国{//转变每一行数据为数组并用split分割字符串,获取个字段音信;string[]
strs = line.Split(‘ ‘);string Phone = strs[0];int LocalID =
Convert.ToInt32(strs[1]);string LocalAddress = strs[2];string
Phonestyle = strs[3];

cmd.Parameters.Clear();cmd.Parameters.Add(new SqlParameter(Phone,
Phone));cmd.Parameters.Add(new SqlParameter(LocalID,
LocalID));cmd.Parameters.Add(new SqlParameter(LocalAddress,
LocalAddress));cmd.Parameters.Add(new SqlParameter(Phonestyle,
Phonestyle));cmd.ExecuteNonQuery();}}

}}}MessageBox.Show(导入成功卡塔尔;}

public static DataTable ExecuteDataTable(SqlConnection conn, string
cmdText,
params SqlParameter[] parameters)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = cmdText;
cmd.Parameters.AddRange(parameters);
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
return dt;
}
}
}

改数据库编码不成,最终忽然想到改改被导入文本文档的编码最终把文本文书档案由ANSI转变为Unicode,最终导入;靠成功了

public static object ToDBValue(this object value)
{
return value == null ? DBNull.Value : value;
}

admin

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注