G
Guest
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
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