vs2015c#查询oracle10g乱码
引用Oracle.ManagedDataAccess.dll数据库为32位10g,字符集为AMERICAN_AMERICA.WE8ISO8859P1
可以查询到数据,不过汉字部分都是乱码。
求解决办法,谢谢。
目前代码如下:
public string getItemInfo(string Code)
{
_putenv("NLS_LANG = AMERICAN_AMRICA.WE8ISO8859P1");//没用
string returnstr = "";
Environment.SetEnvironmentVariable("NLS_LANG", "AMERICAN_AMERICA.WE8ISO8859P1", EnvironmentVariableTarget.Process);//没用
//Create a connection to Oracle
OracleConnection con = new OracleConnection();
//Web.config连接字符串
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
try
{
con.Open();
OracleGlobalization sessionGlob = con.GetSessionInfo();//没用
sessionGlob.Language = "AMERICAN";//没用
con.SetSessionInfo(sessionGlob);//没用
OracleCommand cmmd = new OracleCommand("select * from VIEW_ITEMINFO where code='"+Code + "'", con);
OracleDataAdapter oa = new OracleDataAdapter(cmmd);
System.Data.DataSet ds = new System.Data.DataSet();
oa.Fill(ds, "ItemInfo");
foreach (System.Data.DataRow row in ds.Tables[0].Rows)
{
foreach (System.Data.DataColumn column in ds.Tables[0].Columns)
{
returnstr = returnstr + row[column] + "\t";
}
}
return returnstr;
}
catch
{
return "打开失败!";
}
finally
{
con.Close();
con.Dispose();
}
}