locked
ODP.NET and DataSource Wizard RRS feed

  • Question

  • User-446880360 posted

    Hi,

    I'm (still) using Visual Studio 2010, and need to connect to some Oracle database. At first I did install Oracle Data Access Components (ODAC) - ODAC 12c Release 3 and Oracle Developer Tools for Visual Studio (12.1.0.2.1) latest version that support VS 2010. Open new website, add reference Oracle.DataAccess, and sucessfully created new Data Connection to server using ODP.NET managed driver. On new aspx page add gridview and when I want to create new data source using wizard there is no Oracle source type. 

    Also tried with sql database source type but it is not working since I cant provide selected date value from dropdown list to query.

    What to do and what I did wrong, I guess this is not OK?

    Thanks for help, this is first time I'm using Oracle and VS 2010 combination.

    Friday, September 21, 2018 1:33 PM

All replies

  • User-446880360 posted
            Try
                Dim connstr As String = ConfigurationManager.ConnectionStrings("LIVE").ConnectionString
                Using conn As New OracleConnection(connstr)
                    conn.Open()
                    Using cmd As New OracleCommand
                        cmd.Connection = conn
                        cmd.CommandType = CommandType.Text
                        cmd.CommandText = "SELECT FROM TABLE"
    
                        Using oda As New OracleDataAdapter(cmd)
                            Dim ds As New DataSet()
                            oda.Fill(ds)
                            GridView1.DataSource = ds.Tables(0)
                            GridView1.DataBind()
                        End Using
                    End Using
                End Using
            Catch ex As Exception
            End Try

    At the end I load data to GridView from code behind, and used control value like for any other select, just import

    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types

    It was not that complicated, but I prefer to use wizard for less complex situations. Maybe someone will find this useful.

    Monday, September 24, 2018 12:36 PM
  • User269602965 posted

    Never found the Visual Studio Tools useful at all and prefer just to code it myself.

    I use XML tag for the SQL statement, less fuss with punctuation, string appending and such.

    Imports System.Xml.Linq.XElement
    
    Try
    	Dim connectionString As String = ConfigurationManager.ConnectionStrings("AuthenticatedOracleConnectionString").ConnectionString
    	Dim SQL = _
    		<SQL>
    		 SELECT PRODUCT_CLASS, AMOUNT_ANNUAL_CONTRACT, COUNT, TOTAL_VALUE
    		 FROM TEST.VW_COUNT_CONTRACTS
    	</SQL>
    	Using conn As New OracleConnection(connectionString)
    		Using cmd As New OracleCommand(SQL.Value, conn)
    			conn.Open()
    			Using oda As New OracleDataAdapter(cmd)
    				Dim ds As New DataSet()
    				oda.Fill(ds)
    				Me.RadGrid1.DataSource = ds
    				Me.RadGrid1.MasterTableView.DataSource = ds
    			End Using
    		End Using
    	End Using
    Catch ex As Exception
    	AppCalls.WriteToEventLog(ex, "Selecting VW_COUNT_CONTRACTS", "ContractAdjust.aspx.vb")
    End Try

    Wednesday, September 26, 2018 11:27 PM