Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-28-2012, 04:18 PM   PM User | #1
karlhungus
New to the CF scene

 
Join Date: Apr 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
karlhungus is an unknown quantity at this point
Post How to set parameters for SqlDataSource UpdateCommand

For a Gridview:

I am trying to use a stored procedure for the first time in a SQLDataSource for the UpdateCommand:


<asp:SqlDataSource ID="TECT_DataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>"
ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName %>"
SelectCommand="SELECT MPID, User_Id, Last_Name, First_Name
FROM Scripts.vw_Tect_Exam"
UpdateCommand="P_TECT_UPD_EXAM_ID" UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="MPID" Type="Int32" />
<asp:Parameter Name="User_Id" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>


I am wondering how the UpdateParameters get their values set, since I only specify a name?
The procedure P_TECT_UPD_EXAM_ID expects two parameters as input: "in_MPID" and "in_UserId"
I am also wondering how to map those values to the input parameters for the procedure as the names are different?
karlhungus is offline   Reply With Quote
Old 06-28-2012, 11:56 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
if you are at this level/in this phase you should be using the code behind- you will want to look at this class for more info... but let's say you had a SQL table...
Code:
tbl_Demo
Col 1 -- PK -- INT -- not null
Col 2 -- fName -- varchar(10) -- null
Col 3 -- Age -- INT -- not null
and then these SQL procs (insert and then update)

Code:
CREATE PROC usp_ins_Demo @fName varchar(10), @Age int = 18
AS
INSERT INTO tbl_Demo (fName, Age)
VALUES (@fName, @Age)

CREATE PROC usp_updt_Demo @fName varchar(10), @Age int = 18
AS
UPDATE tbl_Demo
SET Age = @Age
WHERE fName = @fName
*note you should not use a first name as an index, you should use a key, but for example purposes...

and then you would want to call code with the following
*let's say for example sake there are two text boxes "txt_fName" and "txt_Age"
Code:
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmdA = new SqlCommand("usp_ins_Demo", conn);
cmdA.CommandType = CommandType.StoredProcedure;
cmdA.Parameters.Add(new SqlParameter("@fName", txt_fName.Text));
cmdA.Parameters.Add(new SqlParameter("@Age", txt_Age.Text));
*and similar logic for the update
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 07-01-2012, 04:21 PM   PM User | #3
livetecshosting
New Coder

 
Join Date: Jul 2012
Location: Bug Tracking, Isssue Tracking
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
livetecshosting is an unknown quantity at this point
Please take a look at below mentioned article about how to pass parameters using SQLDatasource
http://forums.asp.net/t/1115044.aspx/1
livetecshosting is offline   Reply With Quote
Reply

Bookmarks

Tags
asp.net, procedure, updateparameter

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:28 AM.


Advertisement
Log in to turn off these ads.