locked
Inserting into Oracle Table RRS feed

  • Question

  • User-541003552 posted

    Hi All,

    Can anyone help me with a simple code to insert data into an oracle table with strings, numbers and text from textboxes using normal sql in c#.

    I get the below error.

    ORA-20001: Insert into detb_batch_master failed - ORA-20001: Insert into detb_batch_master failed
    ORA-06512: at "FCCEBG.DETR_UPLOAD_MASTER", line 84
    ORA-04088: error during execution of trigger 'FCCEBG.DETR_UPLOAD_MASTER'
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Data.OracleClient.OracleException: ORA-20001: Insert into detb_batch_master failed - ORA-20001: Insert into detb_batch_master failed
    ORA-06512: at "FCCEBG.DETR_UPLOAD_MASTER", line 84
    ORA-04088: error during execution of trigger 'FCCEBG.DETR_UPLOAD_MASTER'
    
    
    Source Error: 
    
    
    Line 442:            conn1.Open();
    Line 443:            OracleCommand cmd1 = new OracleCommand("INSERT INTO DETB_UPLOAD_MASTER (SOURCE_CODE) VALUES ('Tee')", conn1);
    Line 444:            cmd1.ExecuteNonQuery();
    Line 445:            conn1.Close();
    Line 446:            }
    
    

    Thanks

    Tuesday, July 21, 2015 11:49 AM

All replies

  • User269602965 posted
    Imports System.Xml.Linq.XElement
    
      Public Shared Sub insertSalesUnitInfo(ByVal decQuantity As Decimal, ByVal strDescription As String, ByVal dateDateClosed As DateTime)
        ' Insert Quantity into new row Units table'
        Dim OraConnStr As String = ConfigurationManager.ConnectionStrings("OraConnStr").ConnectionString
        Try
          Dim SQL =
          <SQL>
          INSERT INTO {YOURSCHEMANAME}.UNITS
            (UNITS_SEQ, QUANTITY, DESCRIPTION, DATE_CLOSED, DATE_TODAY) 
          VALUES 
            (UNIT_SEQ.NextVal, :BindVarQuantity, :BindVarDescription, :BindVarDateClosed, SYSDATE)
          </SQL>
          Using conn As New OracleConnection(OraConnStr)
            Using cmd As New OracleCommand(SQL.Value, conn)
              cmd.Parameters.Clear()
              cmd.Parameters.Add("BindVarQuantity", OracleDbType.Decimal, decQuantity, ParameterDirection.Input)
              cmd.Parameters.Add("BindVarDescription", OracleDbType.Varchar2, strDescription, ParameterDirection.Input)
              cmd.Parameters.Add("BindVarDateClosed", OracleDbType.Date, dateDateClosed, ParameterDirection.Input)
              conn.Open()
              cmd.ExecuteNonQuery()
            End Using
          End Using
        Catch ex As Exception
          AppCalls.WriteToEventLog(ex, "Inserting UNITS.QUANTITY failed", "AppCalls.updateUnitsActiveFlag.vb")
        End Try
    End Sub

    converts well to C# with online converter

    Tuesday, July 21, 2015 1:47 PM