473,378 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Separate function for Oracle Commads?

I want to call a function in a different class passing only the sql statement
as argument and I should get the results back. The problem is, I dont know
how to retrieve the datareader contents.

Say I'm calling
Line 1: Dim cmdResult = oracleSqlCommand("select * from Main where
main_id='402'")
Line 2: Dim strTest = cmdResult.Item("title")

I get the following error when executing Line 2: "Invalid operation. The
OracleDataReader is closed. "

How do I get the result set after calling oracleSqlCommand function so
that I can manipulate the database column name, values where I'm calling the
function. Is this possible? Thanks for your time.

Oracle FUNCTION:

Public Shared Function oracleSqlCommand(ByVal sqlCommand As String)
Dim oracleConnection As New OracleConnection

Dim oracleCommand As New OracleCommand
Dim oracleReader As OracleDataReader
Dim connString As String = "Data Source=dsn1;User Id=user;password=#123"

Try
oracleConnection.ConnectionString = connString
oracleConnection.Open()
oracleCommand.CommandText = sqlCommand
oracleCommand.Connection = oracleConnection
oracleReader = oracleCommand.ExecuteReader
Dim resultSet = oracleReader
Return resultSet

oracleReader.Close()
oracleCommand.Dispose()

Catch ex As OracleException
'handle the exception
Return ex.Message

Catch ex As Exception
'handle the exception
Return ex.Message

Finally
If Not (oracleConnection Is Nothing) Then
oracleConnection.Close()
End If

End Try
End Function

Nov 22 '05 #1
6 1800
Varad <Va***@discussions.microsoft.com> wrote:
I want to call a function in a different class passing only the sql statement
as argument and I should get the results back. The problem is, I dont know
how to retrieve the datareader contents.

Say I'm calling
Line 1: Dim cmdResult = oracleSqlCommand("select * from Main where
main_id='402'")
Line 2: Dim strTest = cmdResult.Item("title")

I get the following error when executing Line 2: "Invalid operation. The
OracleDataReader is closed. "
And it's absolutely right. DataReaders are attached to live connections
to the database. You're closing the connection, which makes the reader
useless.
How do I get the result set after calling oracleSqlCommand function so
that I can manipulate the database column name, values where I'm calling the
function. Is this possible? Thanks for your time.


It sounds like you need to return a ResultSet rather than a DataReader.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
hi Jon
Thanks for your reply. How do I use a resultset to return the data from
the called function?

Thanks
Varad

"Jon Skeet [C# MVP]" wrote:
Varad <Va***@discussions.microsoft.com> wrote:
I want to call a function in a different class passing only the sql statement
as argument and I should get the results back. The problem is, I dont know
how to retrieve the datareader contents.

Say I'm calling
Line 1: Dim cmdResult = oracleSqlCommand("select * from Main where
main_id='402'")
Line 2: Dim strTest = cmdResult.Item("title")

I get the following error when executing Line 2: "Invalid operation. The
OracleDataReader is closed. "


And it's absolutely right. DataReaders are attached to live connections
to the database. You're closing the connection, which makes the reader
useless.
How do I get the result set after calling oracleSqlCommand function so
that I can manipulate the database column name, values where I'm calling the
function. Is this possible? Thanks for your time.


It sounds like you need to return a ResultSet rather than a DataReader.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #3
Varad <Va***@discussions.microsoft.com> wrote:
Thanks for your reply. How do I use a resultset to return the data from
the called function?


I meant DataSet rather than ResultSet actually - but you just return
it. Use DataAdapter.Fill to fill the DataSet in the first place, and
then return the DataSet to the caller.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4
Hi Jon
I cannot comprehend what you mean! Pls note that I'm not a .net expert and
I have no clue as to what you are suggesting. Can you write an small example
if you dont mind. Thanks.

V

"Jon Skeet [C# MVP]" wrote:
Varad <Va***@discussions.microsoft.com> wrote:
Thanks for your reply. How do I use a resultset to return the data from
the called function?


I meant DataSet rather than ResultSet actually - but you just return
it. Use DataAdapter.Fill to fill the DataSet in the first place, and
then return the DataSet to the caller.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #5
Varad <Va***@discussions.microsoft.com> wrote:
I cannot comprehend what you mean! Pls note that I'm not a .net expert and
I have no clue as to what you are suggesting. Can you write an small example
if you dont mind. Thanks.


Rather than that, I'd suggest you read an ADO.NET tutorial - there are
loads of them on the net. That's likely to be far better in the long
run than me writing one very specific example.

If you look in MSDN, there's a lot about ADO.NET with examples, too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #6
Thanks Jon. I'm already reading through Ado.Net tutorials and have also got
the dataset working. Now I have to figure out how to extract data from a
dataset.

"Jon Skeet [C# MVP]" wrote:
Varad <Va***@discussions.microsoft.com> wrote:
I cannot comprehend what you mean! Pls note that I'm not a .net expert and
I have no clue as to what you are suggesting. Can you write an small example
if you dont mind. Thanks.


Rather than that, I'd suggest you read an ADO.NET tutorial - there are
loads of them on the net. That's likely to be far better in the long
run than me writing one very specific example.

If you look in MSDN, there's a lot about ADO.NET with examples, too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: free free | last post by:
Hi, i'am writing a python program and now i need to print some stuff. Before print i want to set the text to condensed text and to italic, so i have to send some esc commads to printer. my...
6
by: jcwhui | last post by:
I am building an application that accesses to a customer provided Oracle. I was assuming function-based indices in Oracle 8.0+, but I am wrong. It is only avail since 8i. For now, I can only...
0
by: Bryan Jackson | last post by:
Greetings, (I am an Oracle newbie -- been working with SQLServer for quite some time, however. I'm using Oracle9i and Oracle9i JDeveloper v9.0.3.1 (build 1107) for my programming environment)....
2
by: Mike Hennessy | last post by:
I'm looking for people's opinions and feedback regarding the design of the application tier, and how to best logically separate out the Data Access from the Business Object's. Per the Microsoft...
6
by: Varad | last post by:
I want to call a function in a different class passing only the sql statement as argument and I should get the results back. The problem is, I dont know how to retrieve the datareader contents. ...
1
by: Peter Monica | last post by:
I am trying to calculate distance from a point entered by a user usng a function in Access in a query that calls tables in an Oracle database as well as in Access. I am getting the following...
2
by: John | last post by:
My application needs to call Oracle function using oracle client 9.2. The oracle function returns boolean value from its returned parameter. The name space that I used is system.data.oracleclient....
0
by: truthbajaj | last post by:
Hi, I am using Oracle 9i and Unix on my system and trying to execute a UNIX shell command through external procedure in C. I created a shared lib (libextproc.so) for the following function. ...
8
by: colmkav | last post by:
Can someone tell me how I can access the return value of a function called from Oracle as opposed to a store proc from oracle? my oracle function is get_num_dates_varposfile. I am only used to...
0
by: Svend Jensen | last post by:
Leo wrote: A synonym will do. /Svend
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.