データベース内のデータを選択、削除、更新するためにグリッドビューを使用しています。これらすべての操作を実行するための単一の SP を作成しました。パラメータに基づいて、SP は実行する操作を決定します。
これが私のグリッドのグリッドビュー 画像の画像です http://www.freeimagehosting.net/uploads/0a5de50661.jpg
<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 // Select の場合、最後のパラメーターは 1 になります EXEC Tags.spOnlineTest_Domain "SelectedRow's DomainId), NULL, NULL, 4 // Delete の場合、最後のパラメーターは 4 になります
私の手順には4つのパラメーターがあり、最後のパラメーターはプログラマーによって設定され、実行される操作の種類をプログラムに伝えます。Select の場合、最後のパラメーターのみが Not Null である必要があります。削除の場合、最初と最後のパラメーターを NULL にすることはできません。
私の最初の削除パラメーターは、テーブルの主キーです。ユーザーが行を選択して削除を押すと、この値が渡されます。PropertyName="SelectedValue" を使用しても、ID の正しい値を取得できるかどうかわかりません。
http://www.freeimagehosting.net/uploads/0a5de50661.jpg />