Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to execute multiple pl/sql statement in c#

Status
Not open for further replies.

DanielXIX

Programmer
Jul 31, 2005
18
TR
Hi,
..
..

OracleCommand cmd = this.oraConn.CreateCommand();
cmd.CommandText = sqlStr;
oraConn.Open();
cmd.ExecuteNonQuery();
..
.
.

here ,i try to use batch sql statements in "sqlstr" but i got error.
is it possible ? Any ideas?


thanx



 
If you can, it may be better to create an oracle funtion to execute the multiple request. Do you have the luxary?
 
I did this once for SQL Server, but I am sure the principal would work with Oracle as well.

Code:
const string BATCH_SEPERATOR = "GO";

string[] commands = sqlStr.Split(BATCH_SEPERATOR);
SqlCommand cmd = this.sqlConn.CreateCommand();
sqlConn.Open();
foreach (string commandText in commands)
{
    cmd.CommandText = commandText;
    cmd.ExecuteNonQuery();
}
sqlConn.Close();

The split is a little crude but it worked for me. The issue is if your script has GO anywhere that is not the end of a batch. I'm sure Oracle uses something more sensible like ; anyway.
 
Here is full code for SQL

Code:
[blue]private void[/blue] Page_Load([blue]object[/blue] sender, System.EventArgs e)
{
	SqlConnection objConn = [blue]new[/blue] SqlConnection("server=MyServer;uid=sa;password=sa;database=Northwind;pooling=true;max pool size=6");
	objConn.Open();
	DataSet ds = [blue]new[/blue] DataSet();
	SqlCommand objComm = [blue]new[/blue] SqlCommand("select * from Products go; select * from Categories go");
	SqlDataAdapter objDA = [blue]new[/blue] SqlDataAdapter(objComm.CommandText,objConn);
	objDA.Fill(ds);
	[blue]if[/blue] (objConn.State == System.Data.ConnectionState.Open)
	{
	objConn.Close();
	}
	objDA = [blue]null[/blue];
	objComm = [blue]null[/blue];
	objConn =  [blue]null[/blue];

	[blue]foreach[/blue](DataTable dt [blue]in[/blue] ds.Tables)
	{
	DataGrid dg = [blue]new[/blue] DataGrid();
	dg.DataSource = dt;
	dg.DataBind();
	Page.Controls.Add(dg);
	}
	ds = [blue]null[/blue];
}
 
The BindArray feature of ODP.NET will allow you to run a batch of commands as if they were one statement to the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top