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 DbTriggerHardware(string HardwareType, out string NieuwId)
{
try
{
Database
DbLogon = new Database();
SqlConnection
conn = DbLogon.Opent();
SqlCommand
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText="TriggerHardware";
SqlParameter
ParInput1 = cmd.Parameters.Add("@HdType", SqlDbType.VarChar);
ParInput1.Direction = ParameterDirection.Input;
ParInput1.Value = HardwareType;
SqlParameter
parReturn = cmd.Parameters.Add("@HdType", SqlDbType.VarChar);
parReturn.Direction = ParameterDirection.Output;
cmd.ExecuteReader();
NieuwId
=(cmd.Parameters["@HdType"].ToString());
conn.Close();
}
catch (System.Exception e)
{
throw new
System.ArgumentNullException("", 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 writer1233444443322
PC000001draagbaar 2347678899999
PC000002Acer desktop4334456677665 1 6113
Hi Hugo,
Try using ParameterDirection.ReturnValue and ExecuteNonQuery().
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com www.rthand.com
"Hugo Lefevre" <hu**********@belgacom.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 DbTriggerHardware(string HardwareType, out string NieuwId) { try { Database DbLogon = new Database();
SqlConnection conn = DbLogon.Opent(); SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText="TriggerHardware";
SqlParameter ParInput1 = cmd.Parameters.Add("@HdType", SqlDbType.VarChar);
ParInput1.Direction = ParameterDirection.Input;
ParInput1.Value = HardwareType; SqlParameter parReturn = cmd.Parameters.Add("@HdType", SqlDbType.VarChar);
parReturn.Direction = ParameterDirection.Output;
cmd.ExecuteReader(); NieuwId =(cmd.Parameters["@HdType"].ToString());
conn.Close(); } catch (System.Exception e) { throw new System.ArgumentNullException("", 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 writer1233444443322 PC000001draagbaar 2347678899999 PC000002Acer desktop4334456677665
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
by: Hrvoje Voda |
last post by:
I have this code:
SqlConnection conn = null;
string Table="";
int rCount;
conn = new
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |