更新数据库的GridView和AccessDataSource不起作用

时间:2016-01-22 22:05:00

标签: asp.net webforms

AccessDataSource不会从GridView中获取已编辑的数据,也不会将其保存到数据库中。

有人可以告诉我这里做错了什么吗?更新数据库不起作用。

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/baza.mdb" 
    SelectCommand="SELECT * FROM [users]"
    DeleteCommand="DELETE FROM users WHERE (username = ?)"
    InsertCommand="INSERT INTO users(username, [password], isAdmin) VALUES (?, ?, ?)" 
    OldValuesParameterFormatString="original_{0}"
    UpdateCommand="UPDATE [users] SET [username] = ?, [password] = ?, [isAdmin] = ? WHERE ([username] = ?)">
    <DeleteParameters>
        <asp:Parameter DbType="String" Name="username" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter DbType="String" Name="username" />
        <asp:Parameter DbType="String" Name="password" />
        <asp:Parameter DbType="String" Name="isAdmin" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter DbType="String" Name="username" />
        <asp:Parameter DbType="String" Name="password" />
        <asp:Parameter DbType="String" Name="isAdmin" />
        <asp:Parameter DbType="String" Name="original_username" />
    </UpdateParameters>
</asp:AccessDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="username" DataSourceID="AccessDataSource1" AllowPaging="True" CellPadding="10" ForeColor="#333333" GridLines="None" AllowSorting="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775"></AlternatingRowStyle>
        <Columns>
            <asp:BoundField DataField="username" HeaderText="username" SortExpression="username" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
            <asp:BoundField DataField="password" HeaderText="password" SortExpression="password"></asp:BoundField>
            <asp:BoundField DataField="isAdmin" HeaderText="isAdmin" SortExpression="isAdmin"></asp:BoundField>
        </Columns>
        <EditRowStyle BackColor="#999999"></EditRowStyle>

        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>

        <HeaderStyle  Font-Bold="True" ForeColor="#cecece"></HeaderStyle>

        <PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="#284775"></PagerStyle>

        <RowStyle BackColor="#f8f8f9" ForeColor="#fff"></RowStyle>

        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"></SelectedRowStyle>
    </asp:GridView>

0 个答案:

没有答案