首先,須要保證oracle客戶端服務器的字符集是同樣的,而且保證該字符集支持中文。你能夠使用plsql查看是否亂碼。sql
代碼:數據庫
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.OleDb; namespace Oracle中文 { class Program { static void Main(string[] args) { Console.WriteLine("開始鏈接oraclr數據庫"); string connstring = "Provider=MSDAORA.1;Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.155)(PORT = 1521)))(CONNECT_DATA = (SID = edrsdb))) ;User Id=edrs_process;Password=scgsxxzx"; OleDbConnection conn = new OleDbConnection(connstring); conn.Open(); Console.WriteLine("oracle鏈接成功"); Console.WriteLine("開始讀取中文數據測試是否亂碼"); Console.WriteLine("讀取軟件版本管理-更新內容字段,其結果以下:"); string cmd = "select GXNR from US_RJBBGL where ZJ = 'F6A4A7A7A851C8EEE040007F01004914'"; OleDbCommand oleCmd = new OleDbCommand(cmd, conn); oleCmd.CommandType = System.Data.CommandType.Text; object oresult = oleCmd.ExecuteScalar(); Console.WriteLine(oresult.ToString()); Console.WriteLine("測試中文數據更改是否亂碼"); string updateCmd = "update US_RJBBGL set GXNR = '你好' where ZJ = 'F6A4A7A7A851C8EEE040007F01004914'"; oleCmd.CommandText = updateCmd; oleCmd.ExecuteNonQuery(); Console.WriteLine("數據更改已完成."); Console.Read(); } } }
修改連接字符串的IP、端口、用戶名、密碼以後運行測試效果。服務器