Page 1 of 1

NEW to dotconnect for oracle

Posted: Tue 08 Dec 2009 13:09
by aidanc
Hi,

can I write this kind of code using dotconnect

Dim strconn As String = "Data Source=" + gdatabaseip + ";Initial Catalog=" + gdatabasename + ";integrated security=false;user id=" + guserid + ";password=" + gpassword + ";connect timeout=20 "

Dim cn As New SqlConnection(strconn)

strsql = "select * from emp"
Using cmd As New SqlCommand(strsql, cn)
cmd.ExecuteQuery

what is equalvalent of the above useing dotconnect or does it all have to be done through datatable/dataadapeter classes that they provide.


thanks.

Rgds
Aidan

Posted: Wed 09 Dec 2009 08:07
by Shalex
Once dotConnect for Oracle is installed, you can connect from your application to your database with a connection string using either the Common Programming Model (via DbProviderFactory, refer to MSDN) or the dotConnect for Oracle data provider-specific objects. Here is a sample of using the dotConnect for Oracle objects:

Code: Select all

  Dim myConnString As String = "User Id=scott;Password=tiger;Server=OraServer;"
  Dim mySelectQuery As String = "select * from emp"
  Dim myConnection As New OracleConnection(myConnString)
  Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
  myConnection.Open()
  Try
    Dim myReader As OracleDataReader = myCommand.ExecuteReader()
    ' Always call Read before accessing data.
    While myReader.Read()
      Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
          + myReader.GetString(myReader.GetOrdinal("ENAME")))
    End While
    ' always call Close when done reading.
    myReader.Close()
    ' Close the connection when done with it.
  Finally
    myConnection.Close()
  End Try
For more information, please refer to our tutorials. If you have any further questions, feel free to contact us.