1) we need a stored procedure
---------------------------------------
CREATE PROCEDURE usp_Products_Up date1
(
@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:DetailsVie w ID="DetailsView 1" runat="server" AutoGenerateRow s="False"
DataKeyNames="P roductID"
DataSourceID="S qlDataSource3" Height="50px" Width="125px">
<Fields>
<asp:BoundFie ld DataField="Prod uctID" HeaderText="Pro ductID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "ProductID" />
<asp:BoundFie ld DataField="Prod uctName"
HeaderText="Pro ductName" ReadOnly="True"
SortExpression= "ProductNam e" />
<asp:BoundFie ld DataField="Unit Price" HeaderText="Uni tPrice"
SortExpression= "UnitPrice" />
<asp:BoundFie ld DataField="Unit sInStock"
HeaderText="Uni tsInStock" SortExpression= "UnitsInSto ck" />
<asp:CommandFie ld ShowEditButton= "True" />
</Fields>
</asp:DetailsView >
<asp:SqlDataSou rce ID="SqlDataSour ce3" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
SelectCommand=" SELECT [ProductID], [ProductName], [UnitPrice],
[UnitsInStock] FROM [Products] WHERE ([ProductID] = @ProductID)"
UpdateCommand=" usp_Products_Up date1" UpdateCommandTy pe="StoredProce dure">
<UpdateParamete rs>
<asp:Paramete r Name="UnitPrice " Type="Decimal" />
<asp:Paramete r Name="UnitsInSt ock" Type="Int16" />
<asp:Paramete r Name="ProductID " Type="Int32" />
</UpdateParameter s>
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Grid View1" Name="ProductID "
PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
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