0

我目前在从 GridView 中删除一行时遇到了一个非常奇怪的问题。我有以下代码,它会引发以下异常:

ORA-01008: 并非所有变量都绑定

 <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 是我的 Oracle 表中的一个“数字”字段,我尝试了所有类型的数据类型,目前它是一个“十进制”类型。

4

2 回答 2

1

使用 SqlDataSource 的删除事件并尝试编写以下代码:

e.InputParameters["UNIQUEKEY"] = value;

value 是您要发送到数据库的内容

于 2012-06-20T13:05:54.583 回答
0

自己修复了它,必须将主键添加到 GridView 参数(DATAKEYNAMES)。这是我的代码片段:

 <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>
于 2012-06-19T19:45:54.680 回答