ado.net 操作oracle 数据库 跟操作mssql 的原来基本一样。只是使用不同的命名空间而已。下面举两个例子:
一。 C#读取oracle数据库的表格
///ado.net 读取table 列子 ///需要添加命名空间 : using System.Data.OracleClient //链接字符串 string connString = @"User ID=system;Password=123456;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.118)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))"; //创建链接 OracleConnection conn = new OracleConnection(connString); conn.Open(); string sql = "select * from help"; OracleDataAdapter sda_tab = new OracleDataAdapter(sql, conn); DataSet ds = new DataSet(); sda_tab.Fill(ds); DataTable tb = ds.Tables[0];
二 。 C# 执行 oracle 语句 返回 受影响的行数
string connString = @"User ID=system;Password=123456;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.118)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCL)))"; //创建链接 OracleConnection conn = new OracleConnection(connString); conn.Open(); string sql = "select * from help"; OracleCommand cmd = new OracleCommand(sql, conn); int ret = cmd.ExecuteNonQuery();
时间: 2024-10-12 18:32:22