Oracle Database Interaction Using ODP.NET and ASP.NET: All Ways to Manipulate Data Continued - A beautiful tip when manipulating with “OracleCommand”
(Page 6 of 6 )
In the downloadable solution, I wrote some extra code to delete all the information I inserted using other buttons. Even though it is very simple, it is worthwhile to have a look.
Dim cn As New OracleConnection("User ID=scott;password=tiger;Data
Source=ORCL")
Try
Dim cmd As New OracleCommand("delete from scott.emp
where deptno=40", cn)
cmd.Connection.Open()
Dim rows As Integer = cmd.ExecuteNonQuery()
cmd.Dispose()
Me.lblError.Text = "Deleted " & rows & " newly added rows.."
Catch ex As Exception
Me.lblError.Text = ex.Message
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
You can already analyze the above code fragment. It simply deletes all rows from “scott.emp” for those who are working in department 40. But, the most important statement to concentrate on is the following:
Dim rows As Integer = cmd.ExecuteNonQuery()
Until now, I had not used “ExecuteNonQuery” with a variable. But, in the above statement, I did. It actually returns “number of rows affected by the last DML statement”. This is very useful during certain scenarios, when you really want information about the status of a particular DML statement execution.
Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |