Insert multiple rows into Oracle from .Nethttp://forums.asp.net/t/1756199.aspx/1?Insert+multiple+rows+into+Oracle+from+NetMon, 12 Nov 2012 12:40:11 -050017561994766591http://forums.asp.net/p/1756199/4766591.aspx/1?Insert+multiple+rows+into+Oracle+from+NetInsert multiple rows into Oracle from .Net <p>Hello:</p> <p>I've an ArrayList which contains bulk records and I want to insert all of those in a single statement (or Bulk insert). I know it can be done if I use Oracle.DataAccess (it supports bulk insert). But I'm not gonna use it rather use a single insert statement like below:</p> <pre class="prettyprint">StringBuilder strSQL = new StringBuilder(); conn.Open(); com.Connection = conn; strSQL.Append(&quot;INSERT ALL&quot;); strSQL.Append(&quot; INTO TEST &quot; &#43; &quot; VALUES('&quot; &#43; &quot;ID&quot; &#43; &quot;','&quot; &#43; &quot;Person&quot; &#43; &quot;','&quot; &#43; &quot;Location&quot; &#43; &quot;') &quot; ); strSQL.Append(&quot; INTO TEST &quot; &#43; &quot; VALUES('&quot; &#43; newItems[0].ToString() &#43; &quot;','&quot; &#43; newItems[1].ToString() &#43; &quot;','&quot; &#43; newItems[2].ToString() &#43; &quot;') &quot; ); com.CommandText = strSQL.ToString(); com.ExecuteNonQuery();</pre> <p>The above is generating error. Can anyone help me to figure it out.</p> <p>Thanks/Razin</p> 2012-01-05T13:04:47-05:004767708http://forums.asp.net/p/1756199/4767708.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>Single row insert</p> <p>1. get rid of all the punctuation in string builder, a easy source of errors, and replace with creating SQL inside XML tag and passing that value.</p> <p>2. Pass your variables as BIND VARIABLES and in ODP.NET you do that with named parameters</p> <p>VB example:</p> <pre class="prettyprint">Imports System.Xml.Linq.XElement Public Shared Sub InsertIntoTest(ByVal strID As String, ByVal strPerson As String, ByVal strLocation As String) Dim OraConnStr As String = ConfigurationManager.ConnectionStrings(&quot;{YourOraConnStrName}&quot;).ConnectionString Try Dim SQL = &lt;SQL&gt; INSERT INTO {YourSchemaName}.TEST (ID, Person, Location) VALUES (:strID, :strPerson, :strLocation) &lt;/SQL&gt; Using conn As New OracleConnection(OraConnStr) Using cmd As New OracleCommand(SQL.Value, conn) cmd.Parameters.Clear() cmd.Parameters.Add(&quot;strID&quot;, OracleDbType.Varchar2, strID, ParameterDirection.Input) cmd.Parameters.Add(&quot;strPerson&quot;, OracleDbType.Varchar2, strPerson, ParameterDirection.Input) cmd.Parameters.Add(&quot;strLocation&quot;, OracleDbType.Varchar2, strLocation, ParameterDirection.Input) conn.Open() cmd.ExecuteNonQuery() End Using End Using Catch ex As Exception End Try End Sub</pre> 2012-01-06T01:33:18-05:004768851http://forums.asp.net/p/1756199/4768851.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>Hi Lannie:</p> <p>I said I'm not using ODP .NET (Oracle.DataAccess). And I want to insert multiple rows together&nbsp;to reduce network overhead. I think you've not read my post properly.</p> <p>Thanks/Tanvir&nbsp;</p> 2012-01-06T12:57:04-05:004769487http://forums.asp.net/p/1756199/4769487.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>If you want the best performance and capabilities, use Oracle Data Access</p> <p>ODAC&nbsp;supports BINDING to ARRAYS for inserts as well.</p> <p>&nbsp;</p> 2012-01-06T19:15:34-05:004769624http://forums.asp.net/p/1756199/4769624.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <pre class="prettyprint">Also, INSERT ALL requires a SELECT Statement, but since you are inserting into one table SELECT * FROM DUAL should work.</pre> <pre class="prettyprint">Imports System.Xml.Linq.XElement Public Shared Sub InsertIntoTest(ByVal strID As String, ByVal strPerson As String, ByVal strLocation As String) Dim OraConnStr As String = ConfigurationManager.ConnectionStrings("{YourOraConnStrName}").ConnectionString Try Dim SQL = &lt;SQL&gt; INSERT ALL INTO {YourSchemaName}.TEST VALUES ('ID','Person','Location') INTO {YourSchemaName}.TEST VALUES (:strID, :strPerson, :strLocation) SELECT * FROM DUAL &lt;/SQL&gt; Using conn As New OracleConnection(OraConnStr) Using cmd As New OracleCommand(SQL.Value, conn) cmd.Parameters.Clear() cmd.Parameters.Add("strID", OracleDbType.Varchar2, strID, ParameterDirection.Input) cmd.Parameters.Add("strPerson", OracleDbType.Varchar2, strPerson, ParameterDirection.Input) cmd.Parameters.Add("strLocation", OracleDbType.Varchar2, strLocation, ParameterDirection.Input) conn.Open() cmd.ExecuteNonQuery() End Using End Using Catch ex As Exception End Try End Sub</pre> <pre class="prettyprint">&nbsp;</pre> <pre class="prettyprint">&nbsp;</pre> 2012-01-06T22:12:03-05:005205030http://forums.asp.net/p/1756199/5205030.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>Hi,</p> <p>&nbsp; I'm using the Microsoft visual studio 2010.&nbsp; I cannot see the Oracle.dataaccess.dll.&nbsp; Is that some thing I have to download explicitly.</p> <p>Thanks</p> <p>dds</p> 2012-11-08T13:45:14-05:005205214http://forums.asp.net/p/1756199/5205214.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>Install Oracle ODAC (ODP.NET).&nbsp; You can use the latest version, and during install, select the CLIENT install option.</p> <p>then you can transition from system.data.oracle to oracle.dataaccess.dll</p> <p><a href="http://www.oracle.com/technetwork/developer-tools/visual-studio/downloads/index.html">http://www.oracle.com/technetwork/developer-tools/visual-studio/downloads/index.html</a></p> <p>if you have oracle database on your system, you should install the client in a new Oracle Home directory</p> 2012-11-08T16:47:55-05:005208015http://forums.asp.net/p/1756199/5208015.aspx/1?Re+Insert+multiple+rows+into+Oracle+from+NetRe: Insert multiple rows into Oracle from .Net <p>Thanks&nbsp; this helps me.</p> 2012-11-12T12:40:11-05:00