Solved

SqlDataSource - How to execute the parameterized stored proc within?

Posted on 2006-06-13
5
1,315 Views
Last Modified: 2008-01-09
RE:  .NET 2.0

I'm using a "SqlDataSource" control to try and execute an INSERT stored proc. I have the "SqlDataSource" configured properly...it gets the params for the stored proc from the web forms controls. This was all setup in the wizard provided by the "SqlDataSource" control.

Now I want to click a button and execute the "SqlDataSource" so that it takes the values from the web form and uses them to execute the INSERT stored proc.

How do I just tell the "SqlDataSource" to run?
0
Comment
Question by:VirtueTech
5 Comments
 
LVL 5

Expert Comment

by:Jojo1771
ID: 16899461
It has 4 main functions. Which one?


Insert?

SqlDataSource1.Insert()
0
 

Author Comment

by:VirtueTech
ID: 16899752
I tried that...didn't work.

Here's the error:
"Inserting is not supported by data source 'SqlDataSource1' unless InsertCommand is specified."
0
 
LVL 9

Expert Comment

by:bele04
ID: 16899857
The sqldatasource has four main commands: Select, Insert, Update and Delete.  Which one of these did you set your stored proc to? Make sure you specify the corresponding commandtype(for Select, the SelectCommandType and so on) to StoredProcedure since you are using a stored proc and not a sql statement. then call the corresponding(for Select, SqlDataSource1.Select() and so on) method of your sqldatasource.

0
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 16900177
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnection %>"
InsertCommand="sp_insert" InsertCommandType="StoredProcedure" SelectCommand="SELECT * from mytable" OnInserted="On_Inserted" OnInserting="On_Inserting">
<InsertParameters>
<asp:Parameter Name="MyParam" >
</InsertParameters>
</asp:SqlDataSource>

take a look here for the full documentation
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand(VS.80).aspx

HTH
0
 

Author Comment

by:VirtueTech
ID: 16903343
I was using "SelectCommand" and "SelectCommandType" instead of "InsertCommand" and "InsertCommandType"

When I used the Wizard to setup the params into the Stored Proc it put in those commands. I didn't see a place to change it otherwise. I guess you have to do it after you use the wizard. Or just do it all by hand.

Thanks guys.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question