locked
Create a oracle table through .net RRS feed

  • Question

  • User-471560062 posted

    Dear All,

    How can I create an Oracle table through my Visual Studio .net code?

    Appreciate any help.

    Thanks.

    Manori

    Monday, April 4, 2016 7:26 AM

All replies

  • User269602965 posted

    call an Oracle stored procedure (PLSQL procedure or procedure package)  that has  create table statement and execute immediate clause

    of course create table permission will be required in the schema where the table is built.

    Monday, April 4, 2016 7:09 PM
  • User269602965 posted

    You can also try using code behind form

    Example

    web.config
    
      <connectionStrings>
        <add name="OraConnStr" connectionString="Data Source={YOUR_ORACLE_SID};Persist Security Info=True;User Id={SCHEMA};Password={Password}" providerName="Oracle.DataAccess.Client">
        </add>
      </connectionStrings>
      
      <namespaces>
        <clear />
        <add namespace="Oracle.DataAccess.Client" />
        <add namespace="Oracle.DataAccess.Types" />
      </namespaces>
    
    '***********************************************'
    ' sample code behind page to create table '
    
    Imports System.Xml.Linq.XElement
    
      Public Shared Sub CreateTable()
        ' Create new Table'
        Dim OraConnStr As String = ConfigurationManager.ConnectionStrings("OraConnStr").ConnectionString
        Try
          Dim SQL =
          <SQL>
          CREATE TABLE MYSCHEMANAME.MYTABLENAME
            (COL1 NUMBER(12), COL2 VARCHAR2(32), COL3 DATE) 
          </SQL>
          Using conn As New OracleConnection(OraConnStr)
            Using cmd As New OracleCommand(SQL.Value, conn)
              conn.Open()
              cmd.ExecuteNonQuery()
            End Using
          End Using
        Catch ex As Exception
          AppCalls.WriteToEventLog(ex, "Creating Table failed")
        End Try
    End Sub
      

    Tuesday, April 5, 2016 1:41 PM