0

How to execute multiple select queries with C# on Oracle? I have some queries like

select id from table a
select id from table b

etc.

I do not use ; because when I execute a single query it seems like I am not allowed to use a ; at the end of a query.

I execute it with:

{
    string sqlQuery = System.IO.File.ReadAllText(Settings.applicatiePad + Form_Main.QueryMap + "\\" + queryFile);  //load the textfile with query's
    cmd.Connection = OraConnection.conn;
    cmd.CommandText = sqlQuery;
    cmd.CommandType = CommandType.Text;

    OracleDataAdapter da = new OracleDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);  

    BindingSource bs;
    bs = new BindingSource();
    bs.DataSource = ds.Tables[0].DefaultView;

    bindingNavigator1.BindingSource = bs;
    dataGridView1.DataSource = bs;
}

I want to start with simple select query's but my goal is to have text files with different queries like create, drop en PL/SQL blocks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Hansvb
  • 113
  • 1
  • 1
  • 13
  • For the example SQL you showed, you could use UNION or UNION ALL. [What is the difference between UNION and UNION ALL?](http://stackoverflow.com/a/49928/1115360) – Andrew Morton Feb 26 '17 at 19:33
  • The example was simple. What i realy want to to is something like, create table, fill table, some pl sql and then a select. – Hansvb Feb 26 '17 at 19:35
  • Possible duplicate of [Batch multiple select statements when calling Oracle from ADO.NET](http://stackoverflow.com/questions/1062569/batch-multiple-select-statements-when-calling-oracle-from-ado-net) – OldProgrammer Feb 26 '17 at 19:37
  • Then just write a sqlplus script. DDL statements don't return result sets, so not sure if what you are trying to do really makes 100% sense. – OldProgrammer Feb 26 '17 at 19:40
  • I am tryingvto learn to execute sql querys from c# to Oracle. For now i just need to use select statements but the next step will be multiple querys or scripts. I come from Pascal i build a tool in Pascal which validated a oracle database. I used a lot of select and create and pl sql. I loaded them from a file (multipli files) in a memo component. Richtextbox in c#. Then i could execute them. Now i want to make this with c#. – Hansvb Feb 26 '17 at 20:56
  • Multiple SQL statements can only be executed one at a time. Note that a PL/SQL block is a statement. – mustaccio Feb 26 '17 at 21:22

0 Answers0