OLEDB方式操作oracle数据库

OLEDB方式操作oracle数据库

一.查询语句:

复制代码
using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["local_Orcl"].ConnectionString))
            {
                conn.Open();
                using (OleDbCommand cmd = conn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = "select * from HLB_HIS_REQUISITION";
                        DataTable dt = null;
                        OleDbDataAdapter adapter = new OleDbDataAdapter();
                        adapter.SelectCommand = cmd;
                        dt = new DataTable();
                        adapter.Fill(dt);
                        cmd.Parameters.Clear();

                        dataGridView1.DataSource = dt;
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message.ToString() + "\r\n" + ee.StackTrace.ToString());
                        cmd.Dispose();
                        conn.Close();
                        conn.Dispose();
                    }
                }
            }
复制代码

 

二.插入语句:

复制代码
 using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["local_Orcl"].ConnectionString))
            {
                conn.Open();
                using (OleDbCommand cmd = conn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = "insert into hlb_his_requisition(requisition_id, patient_name, patient_sex, patient_age, patient_bed, charge_name, sample_class, requisition_state)values(1,'张三', 1, 1, 1, 1, 1, 1)";
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show(ee.Message.ToString() + "\r\n" + ee.StackTrace.ToString());
                        cmd.Dispose();
                        conn.Close();
                        conn.Dispose();
                    }
                }
            }
复制代码

 

三.连接字符串:

 <add name="local_Orcl" connectionString="Provider=OraOLEDB.Oracle.1;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.31.11)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User ID=scott;Password=123;Unicode=True"/>


四.是否乱码:

 

五.是否需要安装客户端:

 

posted @   土豆哥  阅读(2334)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2017-09-07 FTP ftp部署遇到问题
2017-09-07 Web Server 在iis上部署webservice基于oracle
点击右上角即可分享
微信分享提示