473,394 Members | 1,806 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,394 software developers and data experts.

SQLDatasource/StoredProc/Dataview Update Command Q..

I have been trying to get a grasp on how I can use a sqlserver storedproc as
the UpdateCommand of a Dataview.

The control (datview / SqlDatasource / Edit control) works great when you
supply it with an adhoc sql statement (somthing that I dont' like to do for
many reasons) and populating the select part with a storedproc works well
also, however I have been unable to find a way to get the update to work with
a paramitized storedproc.

Any clues would be welcome.! (if it just isn't possible could someone also
post that and save me hours of bashing my head against the wall!)

Thanks

Rob


Nov 19 '05 #1
2 1654
Ok.. My big problem was that I was trying to do this without the wizard (damn
I hate having to use those things :)

End code (and it works!) - the big trick probably comes from having column
names and paramters that match.

In this case UpdateInvoiceDetail had 5 parameters and they all got picked up
perfectly!

Code below......

<asp:GridView ID="gridExistingItems" Runat="server" Width="718px"
AutoGenerateColumns="False"
datasourceid="DetailsDataSource"
datakeynames="InvoiceDetailID"
runat="server">
<Columns>
<asp:BoundField DataField="InvoiceDetailID"></asp:BoundField>
<asp:BoundField DataField="Description"></asp:BoundField>
<asp:BoundField DataField="Category"></asp:BoundField>
<asp:BoundField DataField="Quantity"></asp:BoundField>
<asp:BoundField DataField="DateOfCharge"></asp:BoundField>
<asp:BoundField DataField="Amount"></asp:BoundField>
<asp:CommandField ShowSelectButton="True"></asp:CommandField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
</Columns>
</asp:GridView>

<asp:sqldatasource id="DetailsDataSource" runat="server"
SelectCommand="ListInvoiceDetails" UpdateCommand="UpdateInvoiceDetail"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>">
<UpdateParameters>
<asp:Parameter Type="Int32"
Name="InvoiceDetailId"></asp:Parameter>
<asp:Parameter Type="String" Name="Description"></asp:Parameter>
<asp:Parameter Type="String" Name="Category"></asp:Parameter>
<asp:Parameter Type="Decimal" Name="Quantity"></asp:Parameter>
<asp:Parameter Type="Decimal" Name="Amount"></asp:Parameter>
<asp:Parameter Type="DateTime"
Name="DateOfCharge"></asp:Parameter>
</UpdateParameters>
<SelectParameters>
<asp:SessionParameter Name="orderID" Type="Int32"
SessionField="OrderID"></asp:SessionParameter>
<asp:Parameter Type="Int32" DefaultValue="5"
Name="OrderCol"></asp:Parameter>
</SelectParameters>
</asp:sqldatasource>
Nov 19 '05 #2
Well obviously didn't test enough..

Found something interesting when using storedprocs..

The whole process worked until I clicked on the UPDATE button (after an
edit) thenI got a rather surprising error that my parameters didn't match...

Turned on profier and found that the website was passing a parameter I just
wasn't expecting..

@original_InvoiceDetailID

All the other paramters existed.. Includint invoicedetailid, but due to the
fact that this is/was my primary key, the original and new are exactly the
same..

The fix. I created a new parameter for my storedproc (that does nothing)
called @original_InvoiceDetailID and Bam.. it works (completely this time)
HTH

Rob

Nov 19 '05 #3

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

Similar topics

17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
0
by: Ed | last post by:
All of a sudden my previously working code started throwing this error. from the SqlDatasource. I am using C# and Asp.net 2.0. Getting the following error: You have specified that your delete...
0
by: Camel | last post by:
Hi, I'm just learning the new databinding paradigm in ASP.NET 2 and I have a question. What if I want to use 1 SqlDataSource for 2 comboboxes? What I want is a master/detail relationship...
1
by: VB Programmer | last post by:
I have a SqlDataSource I setup on an ASP.NET 2.0 webform. I setup the SELECT statement and it has 1 parameter, @ProductId. How do I, using VB.NET, store the results of that SELECT statement...
1
by: gabe | last post by:
Hi, I have 2 scenarios. (1) works, but (2) doesn't ------------------------------------------------------------ 1) I have sqldatasource control using OracleClient. I'm setting the attributes...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
by: Ganesh | last post by:
Hi There, I've a page with with sqldatasource and detailsview, detailview was assinged to sqldatasource on design time. Now i would like to display a some fileds value in text box. How can i...
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
0
by: =?Utf-8?B?UEs5?= | last post by:
I have a very simple setup that should work fine per documentation. However, my gridview control will not properly update using the updatecommand of the sqldatasource. I've simplified everything...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.