SQL Output Paramter problem

I

Islamegy®

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.StoredProcedure,"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]
,(e-mail address removed)
 
C

Chip

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top