ITPub博客

首页 > 数据库 > Oracle > 48@365---C#用oledb连接Oracle

48@365---C#用oledb连接Oracle

Oracle 作者:rorowell 时间:2014-02-18 17:39:00 0 删除 编辑

由于单位oracle数据库字符集的原因,无论用oracleclient还是odp.net都使得汉字乱码。无奈尝试oledb方式进行连接,居然正常显示了。哎,浪费好多时间,留念!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

using System.Data.OleDb;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con=new OleDbConnection("Provider=OraOLEDB.Oracle.1;User ID=tmp;password=tmp;Data Source=tmp;Persist Security Info=True;Extended Properties='PLSQLRSet=1'");

            OleDbCommand store = new OleDbCommand();
            store.Parameters.Clear();
            store.Connection = con;

            store.CommandType = CommandType.StoredProcedure;
            store.CommandText = "work.posstatus";

            try
            {
                OleDbDataAdapter da = new OleDbDataAdapter(store);

                DataTable dt = new DataTable();
                con.Open();
                da.Fill(dt);
                dataGridView1.DataSource=dt;
            }

            finally
            {
                con.Close();
            }
        }
    }
}

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26079092/viewspace-1117452/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-07-20