1

私はグリッドビューを持っています。これには、DropDownList (EditItemTemplate モードの DDL、ItemTemplate モードのラベル) を持つ templatefield があります。詳細ビューの行の編集を押すと、DDL から任意の値を選択できます (DDL は sqldatasource から入力されます) が、更新を実行しようとすると失敗します。データが提供されていないと見なされるためです。 ...

正確なエラーは次のとおりです (DB は NULL データを拒否します)。

値 NULL を列 'status' のテーブル 'gyumolcs.dbo.orders' に挿入できません。列はヌルを許可しません。更新は失敗します。ステートメントは終了されました。

グリッドビューのコードは次のとおりです。

<!-- language: c# -->
<asp:SqlDataSource ID="orderadminSqlDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
    SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date" 
    DeleteCommand="DELETE FROM orders WHERE (ID = @ID)" 
    UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
    <DeleteParameters>
        <asp:Parameter Name="ID" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="status" />
        <asp:Parameter Name="ID" />
    </UpdateParameters>
</asp:SqlDataSource><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="orderadminSqlDataSource" DataKeyNames="ID" Width="608px" 
        AllowPaging="True" AllowSorting="True" PageSize="15">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" InsertVisible="False" ReadOnly="True" >
            <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="UserName" HeaderText="Felhasználónév" 
                SortExpression="UserName" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:BoundField DataField="Quantity" HeaderText="Mennyiség (kg)" 
                SortExpression="Quantity" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:BoundField DataField="Product" HeaderText="Termék" 
                SortExpression="Product" >
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="Rendelés státusz" SortExpression="status">
                <EditItemTemplate>
                    <!--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>-->

                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="statustypeDDLSqlDataSource" DataTextField="name"
                        DataValueField="ID">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="statustypeDDLSqlDataSource" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
                        SelectCommand="SELECT [ID], [name] FROM [status]">
                    </asp:SqlDataSource>

                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="status" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:BoundField DataField="Date" HeaderText="Dátum" SortExpression="Date" />
        </Columns>
        <PagerSettings PageButtonCount="15" Mode="NumericFirstLast" />
    </asp:GridView>

そして、これが orderadminSqlDataSource のコード (グリッドビューのデータソース) です。

<!-- language: c# -->
    <asp:SqlDataSource ID="orderadminSqlDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>" 
        SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date" 
        DeleteCommand="DELETE FROM orders WHERE (ID = @ID)" 
        UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
        <DeleteParameters>
            <asp:Parameter Name="ID" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="status" />
            <asp:Parameter Name="ID" />
        </UpdateParameters>
    </asp:SqlDataSource>

助けてください、問題がわかりません。前もって感謝します!

4

1 に答える 1