欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ADO.Net对oracle数据库的操作

程序员文章站 2022-05-28 20:05:58
首先要写连接字符串 可以在web.config里写上 [html]       &...

首先要写连接字符串

可以在web.config里写上

[html]
<connectionStrings> 
    <add name="oracleson" connectionString="Data Source=dingsenorcl;Persist Security Info=True;User ID=ds;Password=ds;Unicode=True" providerName="System.Data.OracleClient"/> 
  </connectionStrings> 

<connectionStrings>
    <add name="oracleson" connectionString="Data Source=dingsenorcl;Persist Security Info=True;User ID=ds;Password=ds;Unicode=True" providerName="System.Data.OracleClient"/>
  </connectionStrings>
然后再后台调用

[html]
string orclcon = ConfigurationManager.ConnectionStrings["oracleson"].ConnectionString; 

  string orclcon = ConfigurationManager.ConnectionStrings["oracleson"].ConnectionString;

然后要新建一个数据库连接对象

[html]
OracleConnection conn = new OracleConnection(orclcon) 

OracleConnection conn = new OracleConnection(orclcon)
创建一个OracleCommand对象来对数据库进行操作

[html]
OracleCommand cmd = conn.CreateCommand() 

OracleCommand cmd = conn.CreateCommand()打开连接

[html] view plaincopyprint?conn.Open(); 

conn.Open();操作就行了

[html]
cmd.CommandText = "insert into T_12(AAAA)values(:a)"; 
                    cmd.Parameters.AddWithValue(":a", TextBox1.Text);  //参数替换oracle数据库要用: sqlserver数据库是@ 
                    cmd.ExecuteNonQuery(); 

cmd.CommandText = "insert into T_12(AAAA)values(:a)";
                    cmd.Parameters.AddWithValue(":a", TextBox1.Text);  //参数替换oracle数据库要用: sqlserver数据库是@
                    cmd.ExecuteNonQuery();