473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return parameter of a SQL Store procedure

Dear,

I have a problem : I have a database which contains my data of hardware. The
Id is a varchar and I want at my filling form that my user know which is the
last one. So I made a store procedure in SQL Server with a input parameter
(to select the right hardware e.g. PC for a computer, CD for cdrom, etc) and
the last code would I have become with a return parameter. But when I
execute my program I get an exception :

Parameter 1: '@HdType' of type: String, the property Size has an invalid
size: 0

What do I wrong ?

Thank you very much

Hugo Lefevre

*************** *************** *************** *************** *************** *
*************** *************** *****
Below you find the code and the construction in SQL Server :

the code in C# to execute the store procedure :
-------------------------------------------------

string HardwareType ="'PC%'"

public void DbTriggerHardwa re(string HardwareType, out string NieuwId)
{
try
{
Database
DbLogon = new Database();
SqlConnection
conn = DbLogon.Opent() ;
SqlCommand
cmd = conn.CreateComm and();

cmd.CommandType = CommandType.Sto redProcedure;

cmd.CommandText ="TriggerHardwa re";
SqlParameter
ParInput1 = cmd.Parameters. Add("@HdType", SqlDbType.VarCh ar);

ParInput1.Direc tion = ParameterDirect ion.Input;

ParInput1.Value = HardwareType;
SqlParameter
parReturn = cmd.Parameters. Add("@HdType", SqlDbType.VarCh ar);

parReturn.Direc tion = ParameterDirect ion.Output;

cmd.ExecuteRead er();
NieuwId
=(cmd.Parameter s["@HdType"].ToString());
conn.Close();
}
catch (System.Excepti on e)
{
throw new
System.Argument NullException(" ", e.Message);
}

}

The procedure of the store procedure in SQL Server :
------------------------------------------------------

CREATE PROCEDURE TriggerHardware
(
@HdType varchar(8)
)
AS
declare @HardwareId varchar(8)
select @HardwareId = max(Ha_Id)
from Hardware
where Ha_Id like @HdType
return @HardwareId
GO

Construction of the Table Hardware :
--------------------------------------

Ha_Id varchar(8)
Ha_Type varchar(50)
Ha_Snr varchar(20)

The data of the Table Hardware :
--------------------------------------
Ha_IdHa_TypeHa_ Snr
CD000001cd-dvd writer123344444 3322
PC000001draagba ar 2347678899999
PC000002Acer desktop43344566 77665
Nov 15 '05 #1
1 6126
Hi Hugo,

Try using ParameterDirect ion.ReturnValue and ExecuteNonQuery ().

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Hugo Lefevre" <hu**********@b elgacom.net> wrote in message
news:40******** **************@ news.skynet.be. ..
Dear,

I have a problem : I have a database which contains my data of hardware. The Id is a varchar and I want at my filling form that my user know which is the last one. So I made a store procedure in SQL Server with a input parameter
(to select the right hardware e.g. PC for a computer, CD for cdrom, etc) and the last code would I have become with a return parameter. But when I
execute my program I get an exception :

Parameter 1: '@HdType' of type: String, the property Size has an invalid
size: 0

What do I wrong ?

Thank you very much

Hugo Lefevre

*************** *************** *************** *************** *************** * *************** *************** *****
Below you find the code and the construction in SQL Server :

the code in C# to execute the store procedure :
-------------------------------------------------

string HardwareType ="'PC%'"

public void DbTriggerHardwa re(string HardwareType, out string NieuwId)
{
try
{
Database
DbLogon = new Database();
SqlConnection conn = DbLogon.Opent() ;
SqlCommand
cmd = conn.CreateComm and();

cmd.CommandType = CommandType.Sto redProcedure;

cmd.CommandText ="TriggerHardwa re";
SqlParameter ParInput1 = cmd.Parameters. Add("@HdType", SqlDbType.VarCh ar);

ParInput1.Direc tion = ParameterDirect ion.Input;

ParInput1.Value = HardwareType;
SqlParameter
parReturn = cmd.Parameters. Add("@HdType", SqlDbType.VarCh ar);

parReturn.Direc tion = ParameterDirect ion.Output;

cmd.ExecuteRead er();
NieuwId
=(cmd.Parameter s["@HdType"].ToString());
conn.Close(); }
catch (System.Excepti on e)
{
throw new
System.Argument NullException(" ", e.Message);
}

}

The procedure of the store procedure in SQL Server :
------------------------------------------------------

CREATE PROCEDURE TriggerHardware
(
@HdType varchar(8)
)
AS
declare @HardwareId varchar(8)
select @HardwareId = max(Ha_Id)
from Hardware
where Ha_Id like @HdType
return @HardwareId
GO

Construction of the Table Hardware :
--------------------------------------

Ha_Id varchar(8)
Ha_Type varchar(50)
Ha_Snr varchar(20)

The data of the Table Hardware :
--------------------------------------
Ha_IdHa_TypeHa_ Snr
CD000001cd-dvd writer123344444 3322
PC000001draagba ar 2347678899999
PC000002Acer desktop43344566 77665

Nov 15 '05 #2

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

Similar topics

4
1750
by: Daniel Caetano | last post by:
Hi all, i have a store procedure that i use the return function . Ex. create procedute XX as (statement...) if @@error <> 0 return 1 else return 0 . Inside the vb net i wnat to call that procedure and retrieve that value returned. I´m using command. Is that possible? How can i do it? Or i must to
6
6504
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the table, I have to use SCOPE_IDENTITY(). Any ideas? SqlConnection conn = new SqlConnection(connectionString); conn.Open(); //Create the dataadapter
1
1371
by: Hrcko | last post by:
How to read a parameter from store procedure? I want to get a number of rows for the specific tabel. The parameter is @@ROWCOUNT. Hrcko
3
1839
by: Hrvoje Voda | last post by:
I have this code: SqlConnection conn = null; string Table=""; int rCount; conn = new
1
1273
by: ken | last post by:
Dear all, question 1: IF (NOT EXISTS(SELECT * FROM table) RETURN 1 ELSE RETURN 0 how to get back the return value from stored procedure from ado.net 2.0 i try Dim result As Boolean = command.ExecuteScalar but can't get back
4
2750
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx to a stored procedure on the details2.aspx page. I can successfully pass the values from the listbox control to a
2
2664
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different between RETURN and SELECT is. if exists(select * from users where username = @username and password = @password) BEGIN
8
3233
by: jbonifacejr | last post by:
Hi. I'm sorry to bother all of you, but I have spent two days looking at code samples all over the internet, and I can not get a single one of them to work for me. I am simply trying to get a value returned to the ASP from a stored procedure. The error I am getting is: Item can not be found in the collection corresponding to the requested name...
18
2333
by: orajit | last post by:
I have Created one oracle store procedure .There are total 3 parameters 2 in and 1 out parameter , I need to insert the out parameter into the table . Put when I am firing insert statemet that will insert only one value . Could you tell me how to insert more than one values if your procedure returning two values . My code was little...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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...
0
8202
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. ...
0
8338
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...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
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...

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.