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

using stored procedures in .net

could any one please help me in using the output parameters to retrieve some data from my database to a web form!!
here is a sample code:
stored procedure::

alter proc uid_availability_check
@userid varchar(25),
@tot int output
as
select * from myuserinfo where (myuserinfo.userid=@userid)
set @tot=@@rowcount

c# code::

(here con is my connection to the database)

OleDbCommand mycmd = new OleDbCommand();
mycmd.CommandType = CommandType.StoredProcedure;
mycmd.CommandText = "uid_availability_check";
mycmd.Connection = con;

OleDbParameter p1 = new OleDbParameter();
p1 = mycmd.Parameters.Add("@userid" , OleDbType.VarChar);
p1.Value = enteruserid.Text;
p1.Direction = ParameterDirection.Input;

OleDbParameter p2=new OleDbParameter();
p2.OleDbType=OleDbType.Integer;
p2.Direction= ParameterDirection.Output;
p2=mycmd.Parameters.Add("@tot", OleDbType.Integer);

con.Open();
mycmd.ExecuteNonQuery();
con.close();

label1.Text = p2.Value.ToString();

i know this is wrong....but dont know how to correct it.
and i know to do this using a data reader, without using output parameter.
so...could any one please help me in correcting this.. and tell me how to use the out parameters.

thank you
Apr 22 '07 #1
6 1835
shweta123
692 Expert 512MB
Hi,

This is the right way to get the value from Out Parameter from the Procedure.
Are you getting any error in this or you just want an alternate way of doing this?
Apr 23 '07 #2
Hi,

This is the right way to get the value from Out Parameter from the Procedure.
Are you getting any error in this or you just want an alternate way of doing this?
Hi swetha,
thank you very much for your reply to my second question too.

yes, i'm getting an error while executing this code.
the error looks like this::
Initially, when i didnt included "p2=mycmd.Parameters.Add("@tot",
OleDbType.Integer);", the out parameter stored a null value.

And when i included the above,the error is- the stored procedure
"uid_availability_check" requires another parameter "@tot" which was not
supplied.

Right now i removed the out parameter and solved this problem using data reader.

But, i would like to know how to use the out parameters.
i've tried a lot but couldn't get the result.

could you please help me by sending some sample code that u would write if
u use out parameters.
By the way....is my stored procedure right??
please correct it if its wrong..
thank you very much
cheers and regards
Rohit
Apr 23 '07 #3
shweta123
692 Expert 512MB
hi,

Whatever you have written upto Parameter p1 , I think seems to be Ok.
For Parameter p2 ,you make little change.

Dim p2 As OleDbParameter
p2 = mycmd.CreateParameter()
p2.ParameterName = "@tot"
p2.Direction = ParameterDirection.Output
p2.DbType = DbType.Int32
mycmd.Parameters.Add(p2)

mycmd.ExecuteNonQuery()
Apr 23 '07 #4
shweta123
692 Expert 512MB
hi,

Whatever you have written upto Parameter p1 , I think seems to be Ok.
For Parameter p2 ,you make little change.

Dim p2 As OleDbParameter
p2 = mycmd.CreateParameter()
p2.ParameterName = "@tot"
p2.Direction = ParameterDirection.Output
p2.DbType = DbType.Int32
mycmd.Parameters.Add(p2)

mycmd.ExecuteNonQuery()

Label1.text=p2.value
Apr 23 '07 #5
hi swetha
thank you very much.....
your answer helped me a lot!...thanku
but i could not know the difference between (ur code n my code)

OleDbParameter p2=new OleDbParameter();
p2.OleDbType=OleDbType.Integer;
p2.Direction= ParameterDirection.Output;
p2=mycmd.Parameters.Add("@tot", OleDbType.Integer);

Dim p2 As OleDbParameter
p2 = mycmd.CreateParameter()
p2.ParameterName = "@tot"
p2.Direction = ParameterDirection.Output
p2.DbType = DbType.Int32
mycmd.Parameters.Add(p2)

could you please explain me .

And, when my output parameter is integer( above example)...your code is working.

But, when my output parameter is varchar, i'm getting the following error at runtime.
"String[2]: the Size property has an invalid size of 0."
This error is pointing -"mycmd.ExecuteNonQuery();" code line.

I'ld be very thankful if you solve this problem too

anyways thank you for your code.
cheers n regards
rohit
Apr 24 '07 #6
hi, just had the same problem
u should specify nvarchar's size in the constructor for the SqlParameter
this should work:)
Jul 29 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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
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...
0
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...
0
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...

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.