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

hi, for one of my applications I have implemented something like this

string constr = "User Id=scott;Password=tiger;Data Source=oracle";
OracleConnection con = new OracleConnection(constr);


    public DbCommand CreateCommand ()
    {
          con.Open();
        DbCommand comm = con.CreateCommand();
        comm.CommandType = CommandType.Text;
        return comm;
    }

DbCommand comm = CreateCommand();
comm.CommandText = "select ename, empno from emp";

Then implement Oracle data reader...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.