用了Encoding.Default
在窗体的TEXTBOX里显示无乱码··
但是加到数据库里(加进去的时候也用了Encoding.Default格式化了)
后
在数据库里有点乱码···一些字正常··一些字是?号
。。
。
在窗体的TEXTBOX里显示无乱码··
但是加到数据库里(加进去的时候也用了Encoding.Default格式化了)
后
在数据库里有点乱码···一些字正常··一些字是?号
。。
。
调试欢乐多
令:数据库是啥编码的?
StringBuilder output=newStringBuilder("a,txt",Encoding.GetEncoding("gb2312"));
string rl;
while((rl=sr.ReadLine())!=null)
{
output.Append(rl+"");
}
Console.WriteLine("这个文本文件的内容为:" +output.ToString());
sr.Close();
应该不会丢数据的,再有数据库是nvarchar 还是varchar ?也有一定关系的
private void btnYes_Click(object sender, EventArgs e)
{
if (txtContent.Text.Trim() != "")
{
string Name = string.Format(txtName.Text, Encoding.UTF8);
string Content = string.Format(txtContent.Text, Encoding.UTF8);
string sql = string.Format("insert into BookInfo (BookAuthor,BookName,BookContent) values ('{0}','{1}','{2}')", txtAuther.Text, Name,Content);
SqlCommand cmd = new SqlCommand(sql, DBHelper.connection);
try
{
DBHelper.connection.Open();
int x = cmd.ExecuteNonQuery();
if (x > 0)
{
MessageBox.Show("增加成功", "提示", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("增加失败", "提示", MessageBoxButtons.OK);
}
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
finally
{
DBHelper.connection.Close();
}
} private void btnAdd_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();//创建打开文件的对话框
open.Filter = "txt文本文档|*.txt";// 文件类型筛选
open.RestoreDirectory = true; if (DialogResult.OK == open.ShowDialog())
{
//Text.frm Image.FromFile(
//txtName.Text = open.Title;
string x = Path.GetFileName(open.FileName);
string[] y;
y = x.Split('.');//把文件名以点分隔两边,放入y数组中
this.txtName.Text = "《" + y[0] + "》";
path = open.FileName;
try
{
FileStream fs = new FileStream(path, FileMode.Open);
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
{
txtContent.Text = sr.ReadToEnd();//读数据
}
fs.Close();
}
catch (Exception wrong)
{
MessageBox.Show(wrong.Message);
}
}
}数据库里的列BookAuthor和 BookName是nvarchar
BookContent是ntext
...还是无解...一部分字是?号
自己写个测试 判断一下textbox里有文字时的编码再用那个编码存数据库看看.你自己多试试.
具体如“provide=msdaora;......”