本文整理汇总了C#中Oracle.DataAccess.Client.OracleConnection类的典型用法代码示例。如果您正苦于以下问题:C# OracleConnection类的具体用法?C# OracleConnection怎么用?C# OracleConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OracleConnection类属于Oracle.DataAccess.Client命名空间,在下文中一共展示了OracleConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDbConnection
/// <summary>
/// 根据配置文件中所配置的数据库类型和传入的
/// 数据库链接字符串来创建相应数据库连接对象
/// </summary>
/// <param name="connectionString"></param>
/// <returns></returns>
public static DbConnection CreateDbConnection(string connectionString)
{
DbConnection conn = null;
switch (DbHelper.DbType)
{
case DatabaseType.SqlServer:
conn = new SqlConnection(connectionString);
break;
case DatabaseType.Oracle:
conn = new OracleConnection(connectionString);
break;
case DatabaseType.MySql:
conn = new MySqlConnection(connectionString);
break;
case DatabaseType.Access:
conn = new OleDbConnection(connectionString);
break;
case DatabaseType.SQLite:
conn = new SQLiteConnection(connectionString);
break;
default:
throw new Exception("数据库类型目前不支持!");
}
return conn;
}
示例2: buttonupdate_Click
private void buttonupdate_Click(object sender, EventArgs e)
{
string oradb = "Data Source=XE;User Id=system;Password=admin;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "update pharm.DRUG set D_NAME = '" + updatename.Text + "', MFD = '"+ textBox3.Text +"', EXP= '"+ updateexp.Text + "' , COST ="+ updatecost.Text +", QUANTITY = "+ textBox2.Text + " WHERE DRUG_ID = " + textBox1.Text;
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated == 0)
MessageBox.Show("Record not inserted");
else
MessageBox.Show("Success!");
conn.Dispose();
}
示例3: ReadDataToDataSet
/// <summary>
/// 将数据读取到 DataSet 中.
/// </summary>
public void ReadDataToDataSet()
{
Console.WriteLine("使用DataAdapter,将数据填充到DataSet中,然后脱离数据库,直接对DataSet进行处理。");
// 建立数据库连接.
OracleConnection conn = new OracleConnection(connString);
// 创建一个适配器
OracleDataAdapter adapter = new OracleDataAdapter(SQL, conn);
// 创建DataSet,用于存储数据.
DataSet testDataSet = new DataSet();
// 执行查询,并将数据导入DataSet.
adapter.Fill(testDataSet, "result_data");
// 关闭数据库连接.
conn.Close();
// 处理DataSet中的每一行数据.
foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows)
{
// 将检索出来的数据,输出到屏幕上.
Console.WriteLine("NO:{0} ; Date:{1} ; Money:{2} ",
testRow["NO"], testRow["SALE_DATE"], testRow["SUM_MONEY"]
);
}
}
示例4: getAuthForIdUser
public UsAuth getAuthForIdUser(string email, string passwd)
{
OracleConnection connection = null;
OracleDataReader dr = null;
UsAuth auth = null;
try
{
using (connection = new OracleConnection(OracleHelper.connectionString()))
{
using (var command = new OracleCommand("US_AUTH_GETFOR_USER", connection))
{
connection.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("P_CUR_RESULT", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
command.Parameters.Add("EMAIL", email);
command.Parameters.Add("PASWD", passwd);
using (dr = command.ExecuteReader())
{
if (dr.HasRows)
{
auth = new UsAuth()
{
IdUser = Convert.ToInt32(dr["IDUSER"].ToString()),
Email = dr["EMAIL"].ToString(),
FirstName = dr["FIRSTNAME"].ToString(),
LastName = dr["LASTNAME"].ToString(),
Role = new UsRole()
{
Id = Convert.ToInt32(dr["IDROLE"].ToString()),
Name = dr["NAMEROLE"].ToString()
},
Photo = dr["PHOTO"].ToString(),
ListRoleModule = new DARoleModule().getRoleModuleForRole(Convert.ToInt32(dr["IDROLE"].ToString())),
ListRoleModulePrivilege = new DARoleModulePrivilege().getRoleModulePrivilegeForRole(Convert.ToInt32(dr["IDROLE"].ToString()))
};
}
}
}
}
return auth;
}
catch (Exception e)
{
dr.Dispose();
if (connection.State == ConnectionState.Open)
connection.Dispose();
LogHelper.WriteLog(e);
throw e;
}
finally
{
auth = null;
}
}
示例5: Connect
public void Connect()
{
con = new OracleConnection();
con.ConnectionString = connectionstring;
con.Open();
Console.WriteLine("Connection succesfull");
}
示例6: Connection
private Connection()
{
try
{
string Dsource = "(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)"
+ "(HOST=bd.thronewars.ca)(PORT=1521)))"
+ "(CONNECT_DATA=(SERVICE_NAME=ORCL)))";
String ChaineConnexion = "Data Source=" + Dsource
+ ";User Id=THRONE; Password =Warst";
conn = new OracleConnection(ChaineConnexion);
conn.Open();
if (conn.State.ToString() != "Open")
{
// to do
}
}
catch (OracleException ex)
{
Erreur.ErrorMessage(ex);
}
}
示例7: Limpeza
public bool Limpeza()
{
bool ret = false;
try
{
using (OracleConnection connection = new OracleConnection(RetornoCIP.CNX_C3))
{
OracleCommand command = new OracleCommand("TRUNCATE TABLE CCCTBLBRE", connection);
command.CommandType = CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
if (Utils._logger != null)
Utils._logger.Info("Limpeza ok");
ret = true;
}
}
catch (Exception ex)
{
if (Utils._logger != null)
Utils._logger.Error(ex.Message);
}
return ret;
}
示例8: HaalGebruikersOp
/// <summary>
/// Use only to retrieve user on initialization
/// </summary>
/// <param name="query">The input query</param>
/// <returns>A DataTable containing the results of the query</returns>
public static DataTable HaalGebruikersOp(string query)
{
using (OracleConnection conn = new OracleConnection(connectionstring2))
{
try
{
conn.Open();
OracleCommand cmd = new OracleCommand(query);
cmd.Connection = conn;
try
{
OracleDataReader reader = cmd.ExecuteReader();
DataTable result = new DataTable();
result.Load(reader);
conn.Close();
return result;
}
catch (OracleException ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
catch (OracleException ex)
{
Console.WriteLine(ex.Message);
return new DataTable();
}
}
}
示例9: AddIncident
public static bool AddIncident(Incident i, int missieUID)
{
using (OracleConnection o = new OracleConnection(connstring))
{
using (OracleCommand c = new OracleCommand())
{
try
{
c.Connection = o;
o.Open();
c.CommandText = "INSERT INTO TIncident (Beschrijving) VALUES ('" + i.Beschrijving + "')";
c.ExecuteNonQuery();
c.CommandText = "SELECT MAX(ID) FROM TIncident";
OracleDataReader dr = c.ExecuteReader();
if (dr.Read())
{
c.CommandText = "INSERT INTO TMissie_Incident (MissieID, IncidentID) VALUES ('" + missieUID + "', '" + GetInt(dr[0]) + "')";
c.ExecuteNonQuery();
}
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
finally
{
o.Close();
}
}
}
}
示例10: GetBusinessObject
public IBeheerContextEntity GetBusinessObject(string qry, BeheerContextEntity beheerObject)
{
using (var conn = new OracleConnection(_oradb))
{
conn.Open();
var cmd = new OracleCommand
{
Connection = conn,
CommandText = qry,
CommandType = CommandType.Text
};
cmd.Connection = conn;
var reader = cmd.ExecuteReader();
var smartReader = new SmartDataReader(reader);
BeheerContextEntity businessObject = null;
while (smartReader.Read())
{
businessObject = new BeheerContextEntity
{
Id = smartReader.GetInt32("id"),
DataKeyValue = smartReader.GetString(beheerObject.DataKeyName, ""),
Tablename = beheerObject.Tablename,
DataKeyName = beheerObject.DataKeyName
};
}
return businessObject;
}
}
示例11: OpenDb
public virtual IDb OpenDb()
{
IDbConnection cn = new Oracle.DataAccess.Client.OracleConnection(connString);
//cn.Open();
IDb db = new OrlDb(this, cn);
return db;
}
示例12: button1_Click_1
private void button1_Click_1(object sender, EventArgs e)
{
int a;
a = Convert.ToInt32(textBox4.Text);
a = int.Parse(textBox4.Text);
string oradb = "Data Source=XE;User Id=system;Password=admin;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "update pharm.DRUG set QUANTITY =QUANTITY - " + a + "";
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated == 0)
MessageBox.Show("Record not inserted");
else
MessageBox.Show("Success!");
conn.Dispose();
}
示例13: OracleTransformationProvider
public OracleTransformationProvider(Dialect dialect, string connectionString)
: base(dialect, connectionString)
{
_connection = new OracleConnection();
_connection.ConnectionString = _connectionString;
_connection.Open();
}
示例14: DataTable
public DataTable Consulta
(
string pQuery,
string pConnectionString
)
{
DataTable lTable = new DataTable();
DataSet lDataSet = new DataSet();
OracleConnection lConnection = new OracleConnection(pConnectionString);
try
{
lConnection.Open();
OracleDataAdapter lDataAdapter = new OracleDataAdapter(pQuery, pConnectionString);
lDataAdapter.Fill(lDataSet);
lTable = lDataSet.Tables[0];
return lTable;
}
finally
{
lConnection.Close();
}
}
示例15: ConnectionData
public static OracleConnection ConnectionData()
{
string cnStr = "Data Source=(DESPRIPTION =(ADDPRESS_LIST =(ADDPRESS = (PROTOCOL = TCP)(HOST= localhost)(PORT= = 1521)))(CONNECT_DATA =(SERVICE_NAME = ORCL))); User Id = QUANLY; Password=123456";
cn = new OracleConnection(cnStr);
return cn;
}