Solved

SqlDataSource - How to execute the parameterized stored proc within?

Posted on 2006-06-13
5
1,306 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now