locked
UpdateCommand parameters RRS feed

  • Question

  • User-592976280 posted

    I get error when I try #, @, or : in the following codes. This is C# code in .net 4.0, using Oracle database 10g.

    Exception Details: System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number

    <asp:SqlDataSource ID="SqlDataSource3" runat="server"  
                ConnectionString=...
                ProviderName=...
                SelectCommand="SELECT id, name, hireDate FROM emp" 
                UpdateCommand="UPDATE emp SET name = #name, hireDate = #hire_Date WHERE id = #id">
            <UpdateParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="hire_Date" Type="DateTime" />
                <asp:Parameter Name="id" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    Wednesday, May 25, 2011 10:53 AM

All replies

  • User1332070545 posted

    Hi,

    first try use the column : , then try to reorder parameters in Update command to match the select command (id,name and then hireDate)  

    I am not sure, but just try this.

    Wednesday, May 25, 2011 5:43 PM
  • User269602965 posted

    Try

    <asp:SqlDataSource ID="SqlDataSource3" runat="server"
      ConnectionString=...            
      ProviderName=...            
      SelectCommand="SELECT id, name, hireDate FROM emp"
      UpdateCommand="UPDATE emp SET name = :pName, hireDate = :pHire_Date WHERE id = :pId">
      <SelectParameters></SelectParameters>
      <UpdateParameters>
       <asp:Parameter Name="pName" Type="String" />
       <asp:Parameter Name="pHire_Date" Type="DateTime" />
       <asp:Parameter Name="pId" Type="Decimal" />
      </UpdateParameters>
    </asp:SqlDataSource>

    Wednesday, May 25, 2011 9:38 PM
  • User-592976280 posted

    I try re-ordering the fields as well as using colon, none of that works.

    May be I should use asp:ControlParameter instead of asp:Parameter

    I try the following but it doesn't recognize the control id that I specify. With viewsource the id is name="ctl00$ctl00$ParentContent$ChildContent$GridView2$ctl02$ctl03"

          <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="id" DataSourceID="SqlDataSource3">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="id" HeaderText="id" 
                    InsertVisible="False" ReadOnly="True" SortExpression="id" />
                <asp:BoundField DataField="name" HeaderText="name" 
                    SortExpression="name" />
                <asp:BoundField DataField="hireDate" HeaderText="hireDate" 
                    SortExpression="hireDate" />
            </Columns>
        </asp:GridView>
    
        <asp:SqlDataSource ID="SqlDataSource3" runat="server"   
                ConnectionString=... 
                ProviderName=... 
                SelectCommand="SELECT id, name, hireDate FROM emp"  
                UpdateCommand="UPDATE emp SET name = @name, hireDate = @hire_Date WHERE id = @id"> 
            <UpdateParameters>  
                <asp:ControlParameter Name="id" ControlId="id" PropertyName="Text" />
                <asp:ControlParameter Name="name" ControlId="name" PropertyName="Text" />
                <asp:ControlParameter Name="hireDate" ControlId="hireDate" PropertyName="Text" />
            </UpdateParameters> 
        </asp:SqlDataSource>
     
    What should I use for the ControlId? 

     

    Tuesday, June 7, 2011 9:56 AM