I am using visual studio 2013 and oracle database.I want execute multiple create table queries at once in single oraclecommand is it possible ? I am trying following but not working
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "create table test(name varchar2(50) not null)"+"create table test2(name varchar2(50) not null)";
//+ "create table test3(name varchar2(50) not null)"+"create table test3(name varchar2(50) not null)";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Got error at cmd.ExecuteNonQuery();
In order to execute more than one command put them in
begin ... end;
block. And for DDL statements (likecreate table
) run them withexecute immediate
. This code worked for me:More info: Executing SQL Scripts with Oracle.ODP
Have you tried