locked
Update Error RRS feed

  • Question

  • User-1716494584 posted

    Hello i am tryinng to update gridview but it gives me error i providing code for clear understanding

     <asp:Panel ID="Panel2" runat="server" Width="50%">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" DataSourceID="Tran" AllowPaging="True">
                <Columns>
                    <asp:BoundField DataField="TRNDT" HeaderText="TRNDT" SortExpression="TRNDT" />
                    <asp:BoundField DataField="EMPNO" HeaderText="EMPNO" SortExpression="EMPNO" />
                    <asp:BoundField DataField="TRNCD" HeaderText="TRNCD" SortExpression="TRNCD" />
                    <asp:BoundField DataField="INP_AMT" HeaderText="INP_AMT" SortExpression="INP_AMT" />
                    <asp:BoundField DataField="CAL_AMT" HeaderText="CAL_AMT" SortExpression="CAL_AMT" />
                    <asp:BoundField DataField="ADJ_AMT" HeaderText="ADJ_AMT" SortExpression="ADJ_AMT" />
                    <asp:BoundField DataField="ARR_AMT" HeaderText="ARR_AMT" SortExpression="ARR_AMT" />
                    <asp:BoundField DataField="NET_AMT" HeaderText="NET_AMT" SortExpression="NET_AMT" />
                    <asp:BoundField DataField="CF_SW" HeaderText="CF_SW" SortExpression="CF_SW" />
                    <asp:BoundField DataField="USRCODE" HeaderText="USRCODE" SortExpression="USRCODE" />
                    <asp:BoundField DataField="UPDDT" HeaderText="UPDDT" SortExpression="UPDDT" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="Tran" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand="SELECT TRNDT, EMPNO, TRNCD, INP_AMT, CAL_AMT, ADJ_AMT, ARR_AMT, NET_AMT, CF_SW, USRCODE, UPDDT FROM TRAN" UpdateCommand="UPDATE TRAN SET USRCODE=@USRCODE WHERE EMPNO=@EMPNO"></asp:SqlDataSource>
                    </ContentTemplate>
                </asp:UpdatePanel>
        </asp:Panel>
    



    Friday, April 19, 2013 10:06 AM

All replies

  • User641167949 posted

    Whatz the error msg?  try something like the below code.try including datakeyname to your gridview

    <asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              DataSourceMode="DataSet"
              ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
              SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
              UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title WHERE EmployeeID=@EmployeeID"
              OnUpdated="OnDSUpdatedHandler">
          </asp:SqlDataSource>
    
          <asp:GridView
              id="GridView1"
              runat="server"
              AutoGenerateColumns="False"
              DataKeyNames="EmployeeID"
              AutoGenerateEditButton="True"
              DataSourceID="SqlDataSource1">
              <columns>
                  <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                  <asp:BoundField HeaderText="Last Name" DataField="LastName" />
                  <asp:BoundField HeaderText="Title" DataField="Title" />
              </columns>
          </asp:GridView>
    
          <asp:Label
              id="Label1"
              runat="server">
          </asp:Label>
    private void OnDSUpdatedHandler(Object source, SqlDataSourceStatusEventArgs e) {
        if (e.AffectedRows > 0) {
            // Perform any additional processing, 
            // such as setting a status label after the operation.
            Label1.Text = Request.LogonUserIdentity.Name +
                " changed user information successfully!";    
        }
        else {
            Label1.Text = "No data updated!";
        }
     }



    Friday, April 19, 2013 10:13 AM
  • User-1716253493 posted
    set gv datakeynames to empno, add update parameter empno and usercode. Set all boundfield readonly to true except usercode
    Friday, April 19, 2013 4:40 PM
  • User-1716494584 posted

    This Error rises

    Unhandled exception at line 940, column 13 in http://localhost:23413/ScriptResource.axd?d=DT3YJR8QaqV61-teuz0hgmDZGpkcT3pRIooDouWwyvCi4rynEhVBYtDfqQ1BDFcPgKDRO6sjgddkPumJ2Grxsosl336uXd0o7cG2KeQD2KPJvuRlilDGtex9CC4lfq7UB65ymeJOJD5NX1GvCkeFqQ2&t=ffffffffa5177bee
    
    0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: One or more errors occurred during processing of command.
    
    ORA-00936: missing expression
    
    If there is a handler for this exception, the program may be safely continued.



    Friday, April 19, 2013 5:30 PM
  • User-1716494584 posted

    Now My code is Like this

      <asp:Panel ID="Panel2" runat="server" Width="50%">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" DataSourceID="Tran" AllowPaging="True" DataKeyNames="EMPNO">
                <Columns>
                    <asp:BoundField DataField="TRNDT" HeaderText="TRNDT" SortExpression="TRNDT" />
                    <asp:BoundField DataField="EMPNO" HeaderText="EMPNO" SortExpression="EMPNO" ReadOnly="true"  />
                    <asp:BoundField DataField="TRNCD" HeaderText="TRNCD" SortExpression="TRNCD" />
                    <asp:BoundField DataField="INP_AMT" HeaderText="INP_AMT" SortExpression="INP_AMT" />
                    <asp:BoundField DataField="CAL_AMT" HeaderText="CAL_AMT" SortExpression="CAL_AMT" />
                    <asp:BoundField DataField="ADJ_AMT" HeaderText="ADJ_AMT" SortExpression="ADJ_AMT" />
                    <asp:BoundField DataField="ARR_AMT" HeaderText="ARR_AMT" SortExpression="ARR_AMT" />
                    <asp:BoundField DataField="NET_AMT" HeaderText="NET_AMT" SortExpression="NET_AMT" />
                    <asp:BoundField DataField="CF_SW" HeaderText="CF_SW" SortExpression="CF_SW" />
                    <asp:BoundField DataField="USRCODE" HeaderText="USRCODE" SortExpression="USRCODE" />
                    <asp:BoundField DataField="UPDDT" HeaderText="UPDDT" SortExpression="UPDDT" />
                </Columns>
            </asp:GridView>
            
                    </ContentTemplate>
                </asp:UpdatePanel>
            <asp:SqlDataSource ID="Tran" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand="SELECT TRNDT, EMPNO, TRNCD, INP_AMT, CAL_AMT, ADJ_AMT, ARR_AMT, NET_AMT, CF_SW, USRCODE, UPDDT FROM TRAN" UpdateCommand="UPDATE TRAN SET TRNDT=@TRNDR,TRNCD=@TRNCD, INP_AMT=@INP_AMT, CAL_AMT=@CAL_AMT, ADJ_AMT=@ADJ_AMT, ARR_AMT=@ARR_AMT, NET_AMT=@NET_AMT, CF_SW=@CF_SW, USRCODE=@USRCODE, UPDDT=@UPDDT WHERE EMPNO=@EMPNO">
               
                    </asp:SqlDataSource>
        </asp:Panel>

    But Still it give me same error as i mention in previous post

    Friday, April 19, 2013 5:49 PM
  • User-1716253493 posted
    you have not add update parameters yet in your datasource
    Friday, April 19, 2013 8:17 PM
  • User-1716494584 posted

    Still it gives me same error now my code is like this

     <asp:Panel ID="Panel2" runat="server" Width="50%">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="Tran" DataKeyNames="EMPNO">
                        <Columns>
                            <asp:BoundField DataField="EMPNO" ReadOnly="true" />
                            <asp:CommandField ShowEditButton="True" />
                        </Columns>
                    </asp:GridView>
            <asp:SqlDataSource ID="Tran" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" SelectCommand="SELECT TRNDT, EMPNO, TRNCD, INP_AMT, CAL_AMT, ADJ_AMT, ARR_AMT, NET_AMT, CF_SW, USRCODE, UPDDT FROM TRAN" UpdateCommand="UPDATE TRAN SET USRCODE=@USRCODE TRNCD=@TRNCD WHERE EMPNO=@EMPNO">
              <UpdateParameters>
                  <asp:Parameter Name="TRNCD" Type="Int16" />
                  <asp:Parameter Name="USRCODE" Type="String" />
                  <asp:Parameter Name="EMPNO" Type="Int64" />
               </UpdateParameters>
                    </asp:SqlDataSource>
                    </ContentTemplate>
                </asp:UpdatePanel>
        </asp:Panel>



    Saturday, April 20, 2013 2:39 AM
  • User1610357552 posted

      <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

    check may be script manager not added to source code

    Saturday, April 20, 2013 2:45 AM
  • User-1716494584 posted

    I am Already Used Script Manager

    Saturday, April 20, 2013 2:57 AM
  • User-1716494584 posted

    When Error Genereate it take me to the Script Resource.axd and stuck on the following line

    _endPostBack: function PageRequestManager$_endPostBack(error, executor, data) {
    if (this._request === executor.get_webRequest()) {
    this._processingRequest = false;
    this._additionalInput = null;
    this._request = null;
    }

    var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
    Sys.Observer.raiseEvent(this, "endRequest", eventArgs);
    if (error && !eventArgs.get_errorHandled()) {
    throw error;
    }
    },

    Saturday, April 20, 2013 3:05 AM
  • User-1716253493 posted
    your gv and ds look good now
    Saturday, April 20, 2013 3:34 AM
  • User-1716494584 posted

    But Still having problem

    Saturday, April 20, 2013 4:00 AM