我正在使用 gridview 来选择、删除和更新数据库中的数据。我已经编写了一个 SP 来完成所有这些操作。SP 根据参数决定执行哪个操作。
这是 我的网格 http://www.freeimagehosting.net/uploads/0a5de50661.jpg 的 gridview 图像的图像
<asp:GridView ID="GridView1" runat="server" DataSourceID="dsDomain"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="DomainId" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="DomainId" HeaderText="DomainId"
InsertVisible="False" ReadOnly="True" SortExpression="DomainId">
</asp:BoundField>
<asp:BoundField DataField="Domain" HeaderText="Domain"
SortExpression="Domain">
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" >
</asp:BoundField>
<asp:BoundField DataField="InsertionDate" HeaderText="InsertionDate"
SortExpression="InsertionDate">
</asp:BoundField>
</asp:GridView>
我正在使用的数据源在这里
<asp:SqlDataSource ID="dsDomain" runat="server"
ConnectionString="<%$ ConnectionStrings:conLogin %>"
SelectCommand="Tags.spOnlineTest_Domain"
SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False"
DeleteCommand="Tags.spOnlineTest_Domain" DeleteCommandType="StoredProcedure" OnDeleting="DomainDeleting">
<SelectParameters>
<asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="DomainId" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="Domain" Type="String" />
<asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="Description" Type="String" />
<asp:Parameter DefaultValue="1" Name="OperationType" Type="Byte" />
</SelectParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="GridView1" Name="DomainId"
PropertyName="SelectedValue" Size="4" Type="Int32" />
<asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="Domain" Type="String" /> <asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="" Name="Description" Type="String" /> <asp:Parameter ConvertEmptyStringToNull="true" DefaultValue="4" Name="OperationType" Type="Byte" /> </DeleteParameters> </asp:SqlDataSource>
选择操作工作正常。但是当我试图删除时,它说
过程或函数“spOnlineTest_Domain”需要参数“@Domain”,但未提供
但我提供此参数,如
我的存储过程调用是这样的
EXEC Tags.spOnlineTest_Domain NULL, NULL, NULL, 1 // 对于选择最后一个参数将是 1 EXEC Tags.spOnlineTest_Domain "SelectedRow's DomainId), NULL, NULL, 4 // 对于删除最后一个参数将是 4
我的程序有 4 个参数,其中最后一个参数将由程序员设置,它将告诉程序要执行哪种操作。对于 Select only,最后一个参数必须为 Not Null。对于删除第一个和最后一个参数不能为 NULL。
我的第一个 Delete 参数是表的主键。当用户选择一行并点击删除时,我正在传递这个值。我不确定通过使用 PropertyName="SelectedValue",我能否获得正确的 ID 值。
http://www.freeimagehosting.net/uploads/0a5de50661.jpg />