1) we need a stored procedure
---------------------------------------
CREATE PROCEDURE usp_Products_Update1
(
@UnitPrice money,
@UnitsInStock smallint,
@ProductID int
)
AS
UPDATE Products
SET UnitPrice = @UnitPrice,
UnitsInStock = @UnitsInStock
WHERE ProductID = @ProductID
GO
---------------------------------------
2)Build your details View with your SqlDataSource as the following
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="ProductID"
DataSourceID="SqlDataSource3" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName" ReadOnly="True"
SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice"
SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock"
HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice],
[UnitsInStock] FROM [Products] WHERE ([ProductID] = @ProductID)"
UpdateCommand="usp_Products_Update1" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
You just specify your UpdateCommand as Stored procedure adn pickup your
Procedure.
Also note that Procedure Parameter matches field names with "@" at the
begining in your update procedure
Hope this will help you
Reagrds
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"jk***@charter.net" wrote:
Is it possible to use a stored procedure instead of a SQL statement
with the update command on a detail view in asp.net 2005.
If so, how?? I can't seem to pass parameters into the stored
procedure.
Thanks in advance,
Jason