Code for retrieving/updating data in Oracle database using ASP.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone help me out from the above by giving a code snippnet including the
import namespace directives.

Regards/CS
 
Each code snippnet that is valid for retrieving data from SQLClient should
work but with changing the import to be OracleClient.
Notice that Oracle client should be added to the References node in the
Solution Explorer prior to trying to use it.
 
¤ Can anyone help me out from the above by giving a code snippnet including the
¤ import namespace directives.
¤

You need to add a reference (Project..Add Reference) to the System.Data.OracleClient.dll assembly.

Below is a code snippet that uses the DataReader and DataAdapter:

Dim ConnectionString As String

ConnectionString = "DATA SOURCE=Server;USER ID=userid;PASSWORD=password"

Dim ConnectionOracle As New System.Data.OracleClient.OracleConnection(ConnectionString)
ConnectionOracle.Open()

'**************** Start Data Reader Code ****************

Dim OracleCommand As New System.Data.OracleClient.OracleCommand
OracleCommand.Connection = ConnectionOracle
OracleCommand.CommandText = "Select * from TableName"
OracleCommand.CommandType = CommandType.Text

Dim DataReaderOracle As System.Data.OracleClient.OracleDataReader
DataReaderOracle = OracleCommand.ExecuteReader()

While (DataReaderOracle.Read())
Console.WriteLine(DataReaderOracle.Item(0).ToString)
Console.WriteLine(DataReaderOracle.Item(1).ToString)
End While

DataReaderOracle.Close()

'**************** End Data Reader Code ****************

'**************** Start Data Adapter Code ****************
Dim DataAdapterOracle As New System.Data.OracleClient.OracleDataAdapter("Select * from
TableName", ConnectionOracle)

Dim DataSetOracle As New DataSet("OracleTables")

DataAdapterOracle.Fill(DataSetOracle, "TableName")

Dim DataTableOracle As DataTable
DataTableOracle = DataSetOracle.Tables("TableName")

Dim RowCurrent As DataRow
For Each RowCurrent In DataTableOracle.Rows
Console.WriteLine("{0} {1}", _
RowCurrent(0).ToString, _
RowCurrent(1).ToString)
Next
'**************** End Data Adapter Code ****************

ConnectionOracle.Close()

End Sub


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top