Oracle Database Interaction Using ODP.NET and ASP.NET: All Ways to Manipulate Data - Using multiple DML commands
(Page 4 of 5 )
Let us go through the example first.
Dim cn As New OracleConnection("User
ID=scott;password=tiger;Data Source=ORCL")
Try
Dim cmd As New OracleCommand
cmd.Connection = cn
cmd.Connection.Open()
cmd.CommandText = "insert into emp
(empno,ename,sal,deptno) values (1111,'jag',4500,40)"
cmd.ExecuteNonQuery()
cmd.CommandText = "insert into emp
(empno,ename,sal,deptno) values (2222,'win',2300,40)"
cmd.ExecuteNonQuery()
cmd.CommandText = "insert into emp
(empno,ename,sal,deptno) values (3333,'dhan',3400,40)"
cmd.ExecuteNonQuery()
cmd.Dispose()
Me.lblError.Text = "Succesfully inserted.."
Catch ex As Exception
Me.lblError.Text = ex.Message
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
The above code fragment is very similar to the one that exists in the previous section. The only difference is that I used the INSERT command several times. You need not create separate “OracleCommand” objects for every instance of the INSERT statement. Instead, just change the “CommandText” property and use the ExecuteNonQuery” method to execute it.
If you have several DML commands (of the same type as above), you can execute them using a loop. Even though the above method works in these scenarios, it is quite recommended to have parameter based DML statements (later sections) to be executed with “OracleCommand” together with transaction based controlling. We will examine all of these later.
Next: Multiple DML commands with parameters: Method 1 >>
More ASP.NET Articles
More By Jagadish Chaterjee