Search code examples
c#asp.netoraclecommandsql-delete

ORA-01008: not all variables bound (Delete Event on ASP.net Gridview)


I am currently experiencing a really weird problem with deleting a row from a GridView. I have the following code, and it throws the following exception:

ORA-01008: not all variables bound

 <asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:LinkButton ID="DeleteBTN" runat="server" OnClientClick="return confirm('Are you sure you want to delete this move request?')" CommandName="Delete" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>


   <asp:BoundField DataField="UNIQUEKEY" HeaderText="Unique Key"
                SortExpression="UNIQUEKEY" />

 <asp:SqlDataSource ID="GridViewDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Oracle1ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:Oracle1ConnectionString.ProviderName %>" 

        SelectCommand="SELECT ORIGINATOR, TO_CHAR(REQUESTDATE, 'MM/DD/YYYY') as REQUESTDATE, PARTNUMBER, REQUESTQTY, MOVEFROM, MOVETO, COMPLETEDBY, TO_CHAR(COMPLETION_DATE, 'MM/DD/YYYY') as COMPLETION_DATE, COMMENTS, RESPONSETIME, PROCESS_FLAG, UNIQUEKEY FROM MATERIALMOVEREQUEST WHERE RTRIM(PROCESS_FLAG) = :ProcessFlag ORDER BY REQUESTDATE DESC"
        DeleteCommand="DELETE FROM MATERIALMOVEREQUEST WHERE UNIQUEKEY = :UNIQUEKEY">
        <SelectParameters>
            <asp:ControlParameter ControlID="RequestTypeLabel" DefaultValue="" Name="ProcessFlag" PropertyName="Text" Type="String" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="UNIQUEKEY" Type="Decimal" />
        </DeleteParameters>

UNIQUEKEY is a 'Number' field in my Oracle table and I have tried all kinds of data types where it is currently a 'decimal' type.


Solution

  • Fixed it myself, had to add the primary keys to the GridView parameters (DATAKEYNAMES). Here is my code snippet:

     <asp:GridView ID="MMRGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="UNIQUEKEY" 
            DataSourceID="GridViewDataSource" Width="980px" OnRowDataBound="GridViewRowEventHandler" 
            EmptyDataText="No Data Found" AllowSorting="True">
            <Columns>
                <asp:TemplateField HeaderText="Delete" Visible = "true">
                    <ItemTemplate>
                        <asp:LinkButton ID="DeleteBTN" runat="server" OnClientClick="return confirm('Are you sure you want to delete this move request?')" CommandName="Delete" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>