alex19860224
2015-09-11 02:19 浏览 3.5k

关于连接oracle数据库中OleDbConnection和OracleConnection的问题

当前碰到一个问题,数据库中字段的类型是nvarchar2
程序用OleDbConnection方式连接后用传参方式更新字段内容
using (OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=sima;User ID=vas;Password=vas;min pool size=1;max pool size=100";
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE ROA_CFG_SMS SET CONTENT = :content WHERE ID = 10";
cmd.Parameters.Add(":content", OleDbType.VarChar);
cmd.Parameters[0].Value = ”àâçéèêëîïôœùûÀÂÇÉÈÊËÎÏÔŒÙÛn°€…“;
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();

            object name;
            cmd.CommandText = "SELECT CONTENT FROM ROA_CFG_SMS WHERE ID = 10";
            name = cmd.ExecuteScalar();
            textBox2.Text = name.ToString();
        }

程序用OracleConnection方式连接后用传参方式更新字段内容
using (OracleConnection conn = new OracleConnection())
{
conn.ConnectionString = "Data source=sima;User ID=vas;Pwd=vas";
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE ROA_CFG_SMS SET CONTENT = :content WHERE ID = 10";
cmd.Parameters.Add(":content", OracleType.NVarChar);
cmd.Parameters[0].Value = "àâçéèêëîïôœùûÀÂÇÉÈÊËÎÏÔŒÙÛn°€…";
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();

            object name;
            cmd.CommandText = "SELECT CONTENT FROM ROA_CFG_SMS WHERE ID = 10";
            name = cmd.ExecuteScalar();
            textBox2.Text = name.ToString();
        }

用OleDbConnection方式更新会出现乱码,用OracleConnection方式则正常,当前需要用OleDbConnection方式连接,请问应该怎么解决这个乱码问题呢?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐