locked
unable to update a record from webform in Oracle 11g RRS feed

  • Question

  • User1083102780 posted

    Hi, I am creating a web application using Asp.net with Oracle 11g.  I am able to insert new records and I can't seem to be able to Update the record. To simplify things I shrunk the code to one textbox field below. The code below won't update...it won't generate errors either.  Please help! 

    ---update.aspx---

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
            <asp:TextBox ID="Textbox1"   runat="server"></asp:TextBox>
        <asp:Button ID="Update" runat="server" onclick="UpdateRecord" Text="update" />
    </asp:Content>

    --- update.aspx.cs CODE BEHIND-- 

       protected void UpdateRecord(object sender, EventArgs e)
        {
            using (OracleConnection connect = new OracleConnection(connectionString))
            {
                OracleDataAdapter adapter = new OracleDataAdapter();            
                string sql_update = "UPDATE PROFILE SET FNAME = :myvalue";
                OracleCommand cmd = new OracleCommand(sql_update, connect);
                
                connect.Open();
                
                cmd.Parameters.Add(":myvalue", Textbox1.Text); 
                cmd.ExecuteNonQuery();
                adapter.UpdateCommand = cmd; 
                try
                {
                    ErrorMessage.Text = "Update Successful!";
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }   

     


     

    Friday, May 24, 2013 9:36 AM

Answers

  • User269602965 posted

    Remove colon in line of code

                cmd.Parameters.Add("myvalue", Textbox1.Text);

    Good idea to define your parameter data type and direction as well.

    Imports System.Xml.Linq.XElement
    
      Public Shared Sub updateUnitsActiveFlag(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.CLOB, 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


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 24, 2013 9:20 PM