Oracle Database Interaction Using ODP.NET and ASP.NET: All Ways to Manipulate Data - Using a single DML command at a time
(Page 3 of 5 )
Let us first go through the example first.
Dim cn As New OracleConnection("User ID=scott;password=tiger;Data
Source=ORCL")
Try
Dim cmd As New OracleCommand("insert into emp
(empno,ename,sal,deptno) values (1234,'jag',4500,40)", cn)
cmd.Connection.Open()
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
Those who have already worked with ADO.NET will understand the above code within seconds. It is always a good practice to maintain exception handling in our coding, especially with Oracle database connections. They are very sensitive if you are working in “dedicated” connection mode.
Coming to the above code, I used “OracleConnection” (to connect to the Oracle database) and “OracleCommand” (to specify a DML command) classes. With the help of “OracleCommand”, I can specify any DML command (like INSERT, UPDATE, DELETE, and so on), which does some operation at the Oracle database. It can even contain the “SELECT” statement as explained in my previous articles.
You need to concentrate a bit on the following statement as well:
cmd.ExecuteNonQuery
The above statement specifies to “OracleCommand” that you are not providing any SELECT statement. Instead it is a non-queryable command (DML command). When you execute with “ExecuteNonQuery”, the “OracleCommand” object automatically understands that it need not fetch any information and simply executes the command (DML command).
Next: Using multiple DML commands >>
More ASP.NET Articles
More By Jagadish Chaterjee