473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UpdateCommand of a DetailView

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

Aug 3 '06 #1
1 1515
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

Aug 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike | last post by:
I have a detailview, with several template columns in it. It's setup so that a user views info from a datagrid, and if they want to add another row, they click a button. The button causes a...
1
by: Rich | last post by:
Hello, I can update a dataset from my client app using a dataAdapter.Updatecommand when I add parameter values outside of the param declaration. But If I add the param values inline with the...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
1
by: Luqman | last post by:
The detailview control is combination of textboxes and labels, while detailview is in edit mode, how can I change the textbox value through code ? For example: My detailView has following...
0
by: Luqman | last post by:
I have used a single objectDataSource for GridView and DetailView, and when I load the page, the GridView shows all the entries of Invoice, and DetailView shows the 1st entry of Invoice, thats all...
0
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have a GridView and Dataview controls. If user clicks on a row in GridView, the details will be shown in DetailView. 1/ I want to show in DetalView only details field - without column...
2
by: Luqman | last post by:
Hi, Any Idea how to Display Todays Date in DetailView Template Field while Inserting ? For example: When I click on New Button of DetailView Control, I need to display Today's Date in a...
0
by: LamSoft | last post by:
In the object of detailView, i added a function to check the values during itemUpdating, the source is: protected void test2(object sender, DetailsViewUpdateEventArgs e) { foreach...
0
by: stuart_dent | last post by:
I have a SQL Server table with in Indetity column (value auto generated). I have tried to write my own updatecommand code. I can't get it to work. An error says that says Sku and rid are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.