473,657 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Valu e),
new SqlParameter("@ Title", ddl_title.Selec tedValue),
new SqlParameter("@ Name", txt_Name.Text),
new SqlParameter("@ Address", txt_Address.Tex t),
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.Sel ectedValue),
new SqlParameter("@ Email", txt_Email.Text) ,
new SqlParameter("@ UserName", txt_UserName.Te xt),
new SqlParameter("@ Password", txt_Password.Te xt) };
try
{
int x =
SqlHelper.Execu teNonQuery(conn String,CommandT ype.StoredProce dure,"wsi_Users _Insert",collec tion);
if (x != 0)
{
userid = int.Parse(colle ction[0].Value.ToString ());
return true;
}
else
return false;
}
catch (SqlException) { return false; }

and here is the procedure
------------------------------
CREATE PROCEDURE dbo.wsi_Users_I nsert
(

@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 1166
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.Directio n = ParameterDirect ion.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("ReturnValu e", SqlDbType.Int)
parmReturn.Dire ction = ParameterDirect ion.ReturnValue
Chip

"Islamegy®" <Is******@Priva te.4me> wrote in message
news:et******** ******@TK2MSFTN GP02.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.Valu e),
new SqlParameter("@ Title", ddl_title.Selec tedValue),
new SqlParameter("@ Name", txt_Name.Text),
new SqlParameter("@ Address", txt_Address.Tex t),
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.Sel ectedValue),
new SqlParameter("@ Email", txt_Email.Text) ,
new SqlParameter("@ UserName", txt_UserName.Te xt),
new SqlParameter("@ Password", txt_Password.Te xt) };
try
{
int x =
SqlHelper.Execu teNonQuery(conn String,CommandT ype.StoredProce dure,"wsi_Users _Insert",collec tion);
if (x != 0)
{
userid = int.Parse(colle ction[0].Value.ToString ());
return true;
}
else
return false;
}
catch (SqlException) { return false; }

and here is the procedure
------------------------------
CREATE PROCEDURE dbo.wsi_Users_I nsert
(

@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
1746
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
13363
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? >>> import cx_Oracle as oracle >>> connection = oracle.connect('usr/pwd@tns') >>> cursor = connection.cursor() >>> network_name, = cursor.callproc('my_pkg.get_network_name_sp', ('',)) Traceback (most recent call last): File "<interactive input>", line...
1
1284
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, Sum(ViewOrdrelinjer.Subtotal) AS Total, OrdreStatus.Navn AS Status, Kunder.Firma FROM OrdreStatus INNER JOIN (Kunder INNER JOIN (Ordre INNER JOIN ViewOrdrelinjer ON Ordre.ID = ViewOrdrelinjer.OrdreID) ON Kunder.ID = Ordre.KundeID) ON OrdreStatus.ID =...
5
1758
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 .Add("@City",SqlDbType.char).value = ByCity.SelectedValue end with objConn.Open() ZipCode.DataSource=objCmd.ExecuteReader
8
2009
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 down to this line, as the line of code commented out just beneath it runs fine. Can anyone see why my parameter isn't an object? When I grab the command from SQL profiler and run it in Query Analyzer, I get my output parameter returned with a...
5
1408
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 function ) -Not looking for a big complicated question... ( dont waste a lot of ur time please ) I have been searching for the "Optional" parameter forever in VB.net I have found a pretty down to earth article on why NOT to use them....
1
12303
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 poor soul. Situation: I want to do a lookup using a stored procedure for each value in a Row within a GridView. I use a lookup function in my code behind, evaluating the necessary bound fields. The problem is the SqlDataSource representing...
2
1200
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 its source. Now when the user enters an IDA value thats not in the list of the combobox I want the user to be able to choose whether they add the new IDA into the Database or try entering another IDA. I have the following code in the...
3
1273
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 returned. Thanks Lance
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.