本文整理汇总了C#中OracleConnection.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# OracleConnection.CreateCommand方法的具体用法?C# OracleConnection.CreateCommand怎么用?C# OracleConnection.CreateCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OracleConnection
的用法示例。
在下文中一共展示了OracleConnection.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadBlob
// read the BLOB into file "cs-parser2.cs"
public static void ReadBlob (OracleConnection connection)
{
if (File.Exists(outfilename) == true) {
Console.WriteLine("Filename already exists: " + outfilename);
return;
}
OracleCommand rcmd = connection.CreateCommand ();
rcmd.CommandText = "SELECT BLOB_COLUMN FROM BLOBTEST";
OracleDataReader reader2 = rcmd.ExecuteReader ();
if (!reader2.Read ())
Console.WriteLine ("ERROR: RECORD NOT FOUND");
Console.WriteLine (" TESTING OracleLob OBJECT 2...");
OracleLob lob2 = reader2.GetOracleLob (0);
Console.WriteLine (" LENGTH: {0}", lob2.Length);
Console.WriteLine (" CHUNK SIZE: {0}", lob2.ChunkSize);
byte[] lobvalue = (byte[]) lob2.Value;
if (ByteArrayCompare(bytes1, lobvalue) == true)
Console.WriteLine("bytes1 and bytes2 are equal: good");
else
Console.WriteLine("bytes1 and bytes2 are not equal: bad");
FileStream fs = new FileStream(outfilename, FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(lobvalue);
w.Close();
fs.Close();
lob2.Close ();
reader2.Close ();
}
示例2: SaveBinaryContent
public static int? SaveBinaryContent(int? id, string processName, string fieldName, byte[] content, OracleConnection connection)
{
if (connection == null)
{
throw new ArgumentNullException("connection");
}
using (var command = connection.CreateCommand())
{
command.Parameters.Add("p_Content", content == null ? DBNull.Value : (object)content);
if (id == null || id.Value == 0)
{
command.CommandText = string.Format(CultureInfo.InvariantCulture, @"INSERT INTO """"{0}"""" (""""ProcessName"""", """"FieldName"""", """"Content"""", """"IsRemoved"""") VALUES (:p_ProcessName, :p_FieldName, :p_Content, '0'); RETURNING """"Id"""" INTO :p_Id", OracleNamesTranslator.Translate(Constants.BinaryContentTableName));
var idParam = command.Parameters.Add("p_Id", OracleDbType.Int32, ParameterDirection.Output);
command.Parameters.Add("p_ProcessName", processName == null ? DBNull.Value : (object)processName);
command.Parameters.Add("p_FieldName", fieldName == null ? DBNull.Value : (object)fieldName);
command.ExecuteNonQuery();
id = Convert.ToInt32(idParam.Value, CultureInfo.InvariantCulture);
}
else
{
command.Parameters.Add("p_Id", id.Value);
command.CommandText = string.Format(CultureInfo.InvariantCulture, @"UPDATE """"{0}"""" SET """"Content"""" = :p_Content WHERE """"Id"""" = :p_Id", OracleNamesTranslator.Translate(Constants.BinaryContentTableName));
command.ExecuteNonQuery();
}
}
return id;
}
示例3: CreateCommand
// creates and prepares a new DbCommand object on a new connection
public static OracleCommand CreateCommand()
{
// Obtain the database provider name
string dataProviderName = BalloonShopConfiguration.DbProviderName;
// Obtain the database connection string
string connectionString = BalloonShopConfiguration.DbConnectionString;
// Create a new data provider factory
DbProviderFactory factory = DbProviderFactories.
GetFactory(dataProviderName);
// Obtain a database specific connection object
OracleConnection conn = new OracleConnection();
// Set the connection string
conn.ConnectionString = connectionString;
// Create a database specific command object
OracleCommand comm = conn.CreateCommand();
// DbCommand comm = conn.CreateCommand();
// Set the command type to stored procedure
comm.CommandType = CommandType.StoredProcedure;
//OracleParameter p2 =
//comm.Parameters.Add("refcur_out", OracleDbType.RefCursor);
//p2.Direction = ParameterDirection.Output;
// Return the initialized command object
return comm;
}
示例4: getPais
public List<PaisDTO> getPais()
{
List<PaisDTO> lstPais = new List<PaisDTO>();
Parametros p = new Parametros();
PaisDTO itemPais;
using (OracleConnection con = new OracleConnection(p.oracleConnString().ToString()))
{
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "select IDPAIS, NOMBREPAIS from pais";
using (OracleDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
itemPais = new PaisDTO();
itemPais.idPais = reader.GetInt32(0);
itemPais.nombrePais = reader.GetString(1);
lstPais.Add(itemPais);
}
}
con.Close();
con.Dispose();
}
return lstPais;
}
示例5: button2_Click
private void button2_Click(object sender, EventArgs e)
{
// LotNo.Clear();
// Quantity.Clear();
// Price.Clear();
string _connstring = "Data Source=ORCL;User Id = scott;Password=tiger;";
// decimal _totalRecords;
String name;
try
{
OracleConnection _connObj = new OracleConnection(_connstring);
_connObj.Open();
OracleCommand _cmdObj = _connObj.CreateCommand();
// _cmdObj.CommandText = "SELECT ename from employees where empid = 101";
_cmdObj.CommandText = "SELECT ename from emp";
// _totalRecords = (decimal)_cmdObj.ExecuteScalar();
name = (String)_cmdObj.ExecuteScalar();
MessageBox.Show("Total records:" + name);
textBox1.AppendText("Name: " + name);
_connObj.Close();
_connObj.Dispose();
_connObj = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
示例6: getDepartamento
public List<DepartamentoDTO> getDepartamento(int idPais = -1)
{
List<DepartamentoDTO> lstDepar = new List<DepartamentoDTO>();
Parametros p = new Parametros();
DepartamentoDTO itemDep;
using (OracleConnection con = new OracleConnection(p.oracleConnString().ToString()))
{
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = (idPais != -1) ? "select IDDEPARTAMENTO, IDPAIS, NOMBREDEPARTAMENTO from departamento where IDPAIS = " + idPais.ToString() : "select IDDEPARTAMENTO, IDPAIS, NOMBREDEPARTAMENTO from departamento";
using (OracleDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
itemDep = new DepartamentoDTO();
itemDep.idDepartamento = reader.GetInt32(0);
itemDep.idPais = reader.GetInt32(1);
itemDep.nombreDepartamento = reader.GetValue(2).ToString();
lstDepar.Add(itemDep);
}
}
con.Close();
con.Dispose();
}
return lstDepar;
}
示例7: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (!backgroundWorker1.CancellationPending)
{
try
{
using (var conn = new OracleConnection(textBox1.Text))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT 'OK' FROM DUAL";
var result = (string) cmd.ExecuteScalar();
AppendText(string.Format("{0}: Sql executed OK", DateTime.Now));
}
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
AppendText(string.Format("{0}: Error:{1}", DateTime.Now, ex.Message));
}
for (var i = 0; i < 100; i++)
{
Thread.Sleep(30);
if (backgroundWorker1.CancellationPending) return;
}
}
}
示例8: Save
public static bool Save(List<RoleFunctions> rolefunctions, OracleConnection conn)
{
try
{
bool saved = false;
string query = "INSERT INTO SYSTEMROLEFUNCTIONS (ROLEID, FUNCTIONID) values(:roleid, :functionid)";
using (var command = conn.CreateCommand())
{
command.CommandText = query;
command.CommandType = CommandType.Text;
command.BindByName = true;
// In order to use ArrayBinding, the ArrayBindCount property
// of OracleCommand object must be set to the number of records to be inserted
command.ArrayBindCount = rolefunctions.Count;
command.Parameters.Add(":roleid", OracleDbType.Int32, rolefunctions.Select(rf => rf.RoleId).ToArray(), ParameterDirection.Input);
command.Parameters.Add(":functionid", OracleDbType.Int32, rolefunctions.Select(rf => rf.FunctionId).ToArray(), ParameterDirection.Input);
int result = command.ExecuteNonQuery();
if (result == rolefunctions.Count)
saved = true;
return saved;
}
}
catch(Exception ex)
{
throw ex;
}
}
示例9: GrantConnect
private static void GrantConnect(string username, OracleConnection con)
{
string sql = "GRANT CONNECT TO " + username;
using (var cmd = con.CreateCommand())
{
cmd.CommandText = sql;
cmd.BindByName = true;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
示例10: CreateUser
private static void CreateUser(string username, string pass, OracleConnection con)
{
string sql = "create user " + username + " identified by " + pass;
using (var cmd = con.CreateCommand())
{
cmd.CommandText = sql;
cmd.BindByName = true;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
示例11: ExecuteSql
private static void ExecuteSql(string connectionString, string sql, string schemaName = null)
{
using (var conn = new OracleConnection(connectionString))
using (var command = conn.CreateCommand())
{
conn.Open();
if (!string.IsNullOrWhiteSpace(schemaName))
{
command.CommandText = "ALTER SESSION SET CURRENT_SCHEMA=" + schemaName;
command.ExecuteNonQuery();
}
command.CommandText = sql;
command.ExecuteNonQuery();
}
}
示例12: insertUserOracle
public void insertUserOracle(string user, string password)
{
Parametros p = new Parametros();
using (OracleConnection con = new OracleConnection(p.oracleConnString().ToString()))
{
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO USUARIO(IDUSUARIO, EMAIL, PASSWORD, USERNAME) VALUES(SEQ_CLIENTE.nextval,'" + user + "','" + password + "','" + user + "')";
cmd.ExecuteNonQuery();
con.Close();
con.Dispose();
}
}
示例13: UserExists
private static bool UserExists(string username, OracleConnection con)
{
string sql = "SELECT count(1) from all_users where username=upper(:username)";
using (var cmd = con.CreateCommand())
{
cmd.CommandText = sql;
cmd.BindByName = true;
cmd.CommandType = CommandType.Text;
using (var param = new OracleParameter("username", OracleDbType.Varchar2, ParameterDirection.Input))
{
param.Value = username;
cmd.Parameters.Add(param);
object o = cmd.ExecuteScalar();
return ((decimal)o)!= 0;
}
}
}
示例14: DropUser
private static void DropUser(string username, OracleConnection con)
{
try
{
string sql = "DROP USER " + username;
using (var cmd = con.CreateCommand())
{
cmd.CommandText = sql;
cmd.BindByName = true;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
catch (Exception e)
{
Console.WriteLine("DROP USER failed: {0}", e.Message);
}
}
示例15: ShowVolunteers
protected void ShowVolunteers()
{
string connectionString = GetConnectionString();
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
OracleCommand command = connection.CreateCommand();
string sql = @"SELECT FNAME AS ""FIRST NAME"",LNAME AS ""LAST NAME"",DEGIGNATION AS ""DESIGNATION"",ADDR AS ""ADDRESS"", TEL1, TEL2,EMAIL,CASE SEX WHEN 'M' THEN 'MALE' ELSE 'FEMALE' END AS ""GENDER"",SERVED AS ""COURSES SERVED"" FROM T_VOLUNTEER ORDER BY FNAME";
command.CommandText = sql;
OracleDataReader reader = command.ExecuteReader();
gvVolunteers.DataSource = reader;
gvVolunteers.DataBind();
}
}