------简繁体同时共存的问题(系统是繁体的),请高手指导,谢谢!
用同样的代码,写到sql server数据表里就是乱码,写到access里就是正常的。
注:在sql server字段类型nchar,nvarchar,ntext都设置过,在access里是设置为unicode编码,两者没为什么不同呢?
在web.config的设置是:
<globalization fileEncoding= "utf-8 " requestEncoding= "utf-8 " responseEncoding= "utf-8 " culture= "zh-TW "/>
网页代码是:
<%@ Page Language= "C# " ContentType= "text/html " responseEncoding= "utf-8 "%>
<%@ Import Namespace= "System.Data "%>
<%@ Import Namespace= "System.Data.SqlClient "%>
<%@ Import Namespace= "System.Data.OleDb "%>
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
…..
<script runat= "server " language= "c# ">
string connstr;
public void Page_Init(object sender,EventArgs e)
{
this.btnSave.Click+=new System.EventHandler(btnSaveClick1);
}
public void Page_Load(object sender,EventArgs e)
{
//
connstr= "server=10.142.60.169;database=ud_test;uid=xxx;pwd=yyy ";
//connstr=@ "Provider=Microsoft.Jet.OleDb.4.0;data source= "+Server.MapPath( "../data/test001.mdb ");
}
//access
void btnSaveClick(object sender,EventArgs e)
{
showTxt.Text=txt1.Text;
string sqlAdd= "insert into ut_test001(t001) values( ' "+txt1.Text+ " ') ";
//using
using(OleDbConnection con=new OleDbConnection(connstr))
{
OleDbCommand cmd=new OleDbCommand(sqlAdd,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
//sql server
void btnSaveClick1(object sender,EventArgs e)
{
showTxt.Text=txt1.Text;
string sqlAdd= "insert into ut_test001(t001) values( ' "+txt1.Text+ " ') ";
//using
using(SqlConnection con=new SqlConnection(connstr))
{
SqlCommand cmd=new SqlCommand(sqlAdd,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
</script>
------解决方案--------------------帮顶!
消灭零回复!