Executing Several SqlCommands in a Single OracleConnection
Hi
Can you please let me know if I execute several sql query with one open connection?
For example if I have a code like following:
using System;
using System.Data;
using Oracle.DataAccess.Client;
class OracleCommandSample
{
static void Main()
{
string constr = "User Id=scott;Password=tiger;Data Source=oracle";
OracleConnection con = new OracleConnection(constr);
con.Open();
string cmdQuery = "select ename, empno from emp";
// Create the OracleCommand
OracleCommand cmd = new OracleCommand(cmdQuery);
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
// Execute command, create OracleDataReader object
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
// output Employee Name and Number
Console.WriteLine("Employee Name : " + reader.GetString(0) + " , " +
"Employee Number : " + reader.GetDecimal(1));
}
// Clean up
reader.Dispose();
cmd.Dispose();
con.Dispose();
}
}
Can I create another OracleCommand and run it? like:
string cmdQuery = "select ename, empno from emp";
string cmdQuery2 = "select age from emp";
// Create the OracleCommand
OracleCommand cmd = new OracleCommand(cmdQuery);
// Create the Second OracleCommand
OracleCommand cmd = new OracleCommand(cmdQuery2);
// or even more????
Can you please let me know that if it is ok? I also need your help to create a boolean to check if the connection is open or not? I tried severla method but I could'nt run it.
What I am thinking is creating a GenConnection() method and just calling it one time.is this a good idea?
Thanks for your time