MySql gridview UPDATE命令

时间:2013-03-03 21:56:46

标签: c# mysql .net

我有这个网格:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" 
        GridLines="None" DataKeyNames="id,email,first,last">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" 
                            onclientclick="javascript:return confirm('are you sure you want to delete.');" 
                            Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            <asp:BoundField DataField="id" HeaderText="id" SortExpression="id"/>
            <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
            <asp:BoundField DataField="first" HeaderText="first" SortExpression="first"/>
            <asp:BoundField DataField="last" HeaderText="last" SortExpression="last" />

        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDF5AC" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FCF6C0" />
        <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>

这是SqlDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ClientrConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ClientConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM Client;" 
        DeleteCommand="DELETE FROM Client WHERE id = @id AND email = @email;"
        UpdateCommand="UPDATE Client SET first = @first WHERE id = @id;">

        <DeleteParameters>
            <asp:Parameter Name="id" Type="String" />
            <asp:Parameter Name="email" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="id" Type="String" />
            <asp:Parameter Name="first" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

我执行更新,但值是相同的,不知道为什么会发生?

1 个答案:

答案 0 :(得分:0)

我也试过了。它对我有用。看起来connectionstring存在一些问题。

我已经给了connectionstring这对我有用。

我正在使用MySQL:

ConnectionString="server=localhost;user id=root;password=*****;persistsecurityinfo=True;database=coffeedb" ProviderName="MySql.Data.MySqlClient"