除非指定了UpdateCommand,否则数据源'SqlDataSource1'不支持更新。

时间:2015-07-06 14:03:55

标签: c# asp.net vb.net

如何在VB中配置我的ASP.NET Web应用程序,以便不再出现此错误?

我正在尝试编辑条目,然后点击“更新”以更新我网站上的条目,但随后出现此错误。点击“删除”时出现类似错误。

我的Web应用程序上有以下配置的数据源数据表:

<h2>
    Sales
</h2>
<p>    
    <asp:TextBox ID="TextBox1" runat="server">Hello</asp:TextBox>
</p>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" 

EmptyDataText="There are currently no sales reported in this location's database." 
AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" 
GridLines="None">

        <AlternatingRowStyle BackColor="White" />

        <Columns>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField ShowSelectButton="True" />

            <asp:BoundField DataField="Salesperson" HeaderText="Salesperson" 
                SortExpression="Salesperson" />
            <asp:BoundField DataField="VIN" HeaderText="VIN" SortExpression="VIN" />
            <asp:BoundField DataField="Sale_Price" HeaderText="Sale_Price" 
                SortExpression="Sale_Price" />
            <asp:BoundField DataField="MSRP" HeaderText="MSRP" SortExpression="MSRP" />
            <asp:BoundField DataField="Commission_Rate" HeaderText="Commission_Rate" 
                SortExpression="Commission_Rate" />
            <asp:BoundField DataField="Commission_Earned" HeaderText="Commission_Earned" 
                SortExpression="Commission_Earned" />
        </Columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 

SelectCommand="SELECT [Salesperson], [VIN], [Sale Price] AS Sale_Price, [MSRP], [Commission Rate] AS Commission_Rate, [Commission Earned] AS Commission_Earned FROM [Sales]">
    </asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

除非在SqlDataSource的属性中指定一个部分,否则SqlDataSource对象无法知道更新应用程序表的确切方法。数据源上的UpdateCOmmand属性的一个非常粗略的示例可能是

<asp:SqlDataSource id=SqlDataSource1
    ...other stuff omitted..
    UpdateCOmmand='UPDATE MyAppTable Set Field=@Value, OtherField=@OtherValue Where ID=@MyId'
    ...
 >
</asp:SqlDataSource>

然而,再一次,命令的细节是您需要提供的。 ASP.NET可以触发命令,但你必须提供内核,螺母和螺栓才能使它工作。