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

SQL Output Paramter problem

When i call stored procedure which have an output paramter, t'm unable to
get the value
How could i fix it??

here is the method....
----------------------------
userid = 0;
SqlParameter[] collection = new SqlParameter[]
{
new SqlParameter("@ID",DBNull.Value),
new SqlParameter("@Title", ddl_title.SelectedValue),
new SqlParameter("@Name", txt_Name.Text),
new SqlParameter("@Address", txt_Address.Text),
new SqlParameter("@Tel1", txt_Tel.Text),
new SqlParameter("@Tel2", txt_AltTel.Text),
new SqlParameter("@Fax", txt_Fax.Text),
new SqlParameter("@Mobile", txt_Mobile.Text),
new SqlParameter("@City", txt_City.Text),
new SqlParameter("@Country", ddl_Country.SelectedValue),
new SqlParameter("@Email", txt_Email.Text),
new SqlParameter("@UserName", txt_UserName.Text),
new SqlParameter("@Password", txt_Password.Text) };
try
{
int x =
SqlHelper.ExecuteNonQuery(connString,CommandType.S toredProcedure,"wsi_Users_Insert",collection);
if (x != 0)
{
userid = int.Parse(collection[0].Value.ToString());
return true;
}
else
return false;
}
catch (SqlException) { return false; }

and here is the procedure
------------------------------
CREATE PROCEDURE dbo.wsi_Users_Insert
(

@ID int OUTPUT,

@Title varchar (10) ,

@Name varchar (100) ,

@Address varchar (500) ,

@Tel1 varchar (15) ,

@Tel2 varchar (15) ,

@Fax varchar (15) ,

@Mobile varchar (15) ,

@City varchar (50) ,

@Country int ,

@Email varchar (50) ,

@UserName varchar (50) ,

@Password varchar (50)
)
AS

INSERT INTO dbo.[Users]
(
[Title]
,[Name]
,[Address]
,[Tel1]
,[Tel2]
,[Fax]
,[Mobile]
,[City]
,[Country]
,[email]
,[UserName]
,[Password]
)
VALUES
(
@Title
,@Name
,@Address
,@Tel1
,@Tel2
,@Fax
,@Mobile
,@City
,@Country
,@Email
,@UserName
,@Password
)

-- Get the identity value
SET @ID = SCOPE_IDENTITY()
GO
Apr 16 '06 #1
1 1156
You need to set the sqlparameter to output as well. Not sure how to do it
using your syntax, but this will work

dim parmID as sqlparameter
parmID = cmd.Parameters.Add("@ID", SqlDbType.Int)
parmID.Direction = ParameterDirection.Output

Then retrieve the value with parmID.value.

Your could also use the SQL return value to pass an integet back. In your
proc:

RETURN @@identity -- as the exit line in your proc

then in .NET
parmReturn = cmd.Parameters.Add("ReturnValue", SqlDbType.Int)
parmReturn.Direction = ParameterDirection.ReturnValue
Chip

"Islamegy®" <Is******@Private.4me> wrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
When i call stored procedure which have an output paramter, t'm unable to
get the value
How could i fix it??

here is the method....
----------------------------
userid = 0;
SqlParameter[] collection = new SqlParameter[]
{
new SqlParameter("@ID",DBNull.Value),
new SqlParameter("@Title", ddl_title.SelectedValue),
new SqlParameter("@Name", txt_Name.Text),
new SqlParameter("@Address", txt_Address.Text),
new SqlParameter("@Tel1", txt_Tel.Text),
new SqlParameter("@Tel2", txt_AltTel.Text),
new SqlParameter("@Fax", txt_Fax.Text),
new SqlParameter("@Mobile", txt_Mobile.Text),
new SqlParameter("@City", txt_City.Text),
new SqlParameter("@Country", ddl_Country.SelectedValue),
new SqlParameter("@Email", txt_Email.Text),
new SqlParameter("@UserName", txt_UserName.Text),
new SqlParameter("@Password", txt_Password.Text) };
try
{
int x =
SqlHelper.ExecuteNonQuery(connString,CommandType.S toredProcedure,"wsi_Users_Insert",collection);
if (x != 0)
{
userid = int.Parse(collection[0].Value.ToString());
return true;
}
else
return false;
}
catch (SqlException) { return false; }

and here is the procedure
------------------------------
CREATE PROCEDURE dbo.wsi_Users_Insert
(

@ID int OUTPUT,

@Title varchar (10) ,

@Name varchar (100) ,

@Address varchar (500) ,

@Tel1 varchar (15) ,

@Tel2 varchar (15) ,

@Fax varchar (15) ,

@Mobile varchar (15) ,

@City varchar (50) ,

@Country int ,

@Email varchar (50) ,

@UserName varchar (50) ,

@Password varchar (50)
)
AS

INSERT INTO dbo.[Users]
(
[Title]
,[Name]
,[Address]
,[Tel1]
,[Tel2]
,[Fax]
,[Mobile]
,[City]
,[Country]
,[email]
,[UserName]
,[Password]
)
VALUES
(
@Title
,@Name
,@Address
,@Tel1
,@Tel2
,@Fax
,@Mobile
,@City
,@Country
,@Email
,@UserName
,@Password
)

-- Get the identity value
SET @ID = SCOPE_IDENTITY()
GO

Apr 16 '06 #2

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

Similar topics

3
by: jw56578 | last post by:
I know that you can retrieve whether a parameter is for output buy way of the "isoutparam" field, but is there anything that tells you whether a parameter is input/output? thanks
4
by: infidel | last post by:
I have a stored procedure that has a single output parameter. Why do I have to pass it a string big enough to hold the value it is to receive? Why can't I pass an empty string or None? >>>...
1
by: Eirik Eldorsen | last post by:
I've made a query which works fine. My problem is that Access ask for a paramter value when I run the query, and I can't understand why. The query: SELECT Ordre.ID, Ordre.OpprettetDato,...
5
by: tshad | last post by:
I can't seem to find where to reset the parameter list. Dim objCmd as New SqlCommand(CommandText,objConn) with objCmd.Parameters .Add("@StateCode",SqlDbType.Char,2).value = ByState.SelectedValue...
8
by: Patreek | last post by:
Hi, On the line where I'm assigning RecordCount to be the value of my output parameter, I'm getting the generic "Object reference not set to an instance of an object" error. I've isolated it...
5
by: Miro | last post by:
This qustion is probably for people who have created large apps with subs / or functions that have a lot of parameters and used in a lot of places in ur whole app. ( lets say its ur own library...
1
by: John Bailo | last post by:
This is a my solution to getting an Output parameter from a SqlDataSource. I have seen a few scant articles but none of them take it all the way to a solution. Hopefully this will help some...
2
by: Garx | last post by:
Hi Guys, This is my first post so bear with me :) I am running Access 2003 and am still feeling my way around it. I have a form (FORM_IDL) that uses a combobox (cboIDA) which uses a query as...
3
by: araman | last post by:
i have a simple paramter query. one of the fields is called vendors. the criteria is "Like is there a way to construct the query in which "like " but if it is left blank then all record are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.