473,831 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get return value from sp when using OleDbConnection

As subject, if the sp returns a recordset, i can use OlbDbAdapter to get it,
but how about just a return value from sp, e.g. 0 - successful; 1 - error

like
lter proc UpdateJobItemSt atus @JobItemID as bigint, @Status as int as

BEGIN
Begin Tran

-- Fail => locked, release locked, increase NoOfFailure
If @Status = 4
BEGIN
Update OutboundQueueIt em set Status = @Status, NoOfFailure=NoO fFailure+1
where JobItemID = @JobItemID
IF (@@ERROR <> 0) GOTO ERR_HANDLER
END
ELSE
BEGIN
Update OutboundQueueIt em set Status = @Status where JobItemID = @JobItemID
IF (@@ERROR <> 0) GOTO ERR_HANDLER
END

Commit Tran
RETURN 0
ERR_HANDLER:
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
RETURN 1

END

=============== =============== =============

OleDbCommand oleCommand = new OleDbCommand();

oleCommand.Comm andText = "UpdateJobItemS tatus";

oleCommand.Comm andType = CommandType.Sto redProcedure;

oleCommand.Conn ection = conn;

OleDbParameter paramJobItemID = new OleDbParameter( "@JobItemID ",
OleDbType.BigIn t, 8, ParameterDirect ion.Input, false, 0, 0, "JobItemID" ,
DataRowVersion. Current, lngJobItemID);

OleDbParameter paramStatus = new OleDbParameter( "@Status",
OleDbType.Integ er, 4, ParameterDirect ion.Input, false, 0, 0, "Status",
DataRowVersion. Current, intStatus);

oleCommand.Para meters.Add(para mJobItemID);

oleCommand.Para meters.Add(para mStatus);
......
......


Nov 15 '05 #1
3 7106
You'll want to use Either ReturnValue or Output as parameter type...that
should fix it for you.
"Mullin Yu" <mu*******@ctil .com> wrote in message
news:u0******** ******@TK2MSFTN GP09.phx.gbl...
As subject, if the sp returns a recordset, i can use OlbDbAdapter to get it, but how about just a return value from sp, e.g. 0 - successful; 1 - error

like
lter proc UpdateJobItemSt atus @JobItemID as bigint, @Status as int as

BEGIN
Begin Tran

-- Fail => locked, release locked, increase NoOfFailure
If @Status = 4
BEGIN
Update OutboundQueueIt em set Status = @Status, NoOfFailure=NoO fFailure+1
where JobItemID = @JobItemID
IF (@@ERROR <> 0) GOTO ERR_HANDLER
END
ELSE
BEGIN
Update OutboundQueueIt em set Status = @Status where JobItemID = @JobItemID IF (@@ERROR <> 0) GOTO ERR_HANDLER
END

Commit Tran
RETURN 0
ERR_HANDLER:
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
RETURN 1

END

=============== =============== =============

OleDbCommand oleCommand = new OleDbCommand();

oleCommand.Comm andText = "UpdateJobItemS tatus";

oleCommand.Comm andType = CommandType.Sto redProcedure;

oleCommand.Conn ection = conn;

OleDbParameter paramJobItemID = new OleDbParameter( "@JobItemID ",
OleDbType.BigIn t, 8, ParameterDirect ion.Input, false, 0, 0, "JobItemID" ,
DataRowVersion. Current, lngJobItemID);

OleDbParameter paramStatus = new OleDbParameter( "@Status",
OleDbType.Integ er, 4, ParameterDirect ion.Input, false, 0, 0, "Status",
DataRowVersion. Current, intStatus);

oleCommand.Para meters.Add(para mJobItemID);

oleCommand.Para meters.Add(para mStatus);
.....
.....

Nov 15 '05 #2
I got error:
Procedure or function UpdateJobItemSt atus has too many arguments specified.

try

{

long lngJobItemID = 200401130000140 01;

int intStatus = 4;

ICWLogon.clsICL ogon oLogon = new ICWLogon.clsICL ogonClass();

string rtn = oLogon.Logon("e dms3", "edms3", "",
ICWLogon.eLogon Mode.eOnlineMod e);

Console.WriteLi ne("rtn: " + rtn);

string dbstring = oLogon.Database Conn.Connection String + ";database= " +
oLogon.Database Conn.DefaultDat abase;

// set up connection information

OleDbConnection oleConn = new OleDbConnection (dbstring);

oleConn.Open();

OleDbCommand oleCommand = new OleDbCommand();

oleCommand.Comm andText = "UpdateJobItemS tatus";

oleCommand.Comm andType = CommandType.Sto redProcedure;

oleCommand.Conn ection = oleConn;

// create the input parameter

OleDbParameter paramJobItemID = new OleDbParameter( "@JobItemID ",
OleDbType.BigIn t, 8, ParameterDirect ion.Input, false, 0, 0, "JobItemID" ,
DataRowVersion. Current, lngJobItemID);

OleDbParameter paramStatus = new OleDbParameter( "@Status",
OleDbType.Integ er, 4, ParameterDirect ion.Input, false, 0, 0, "Status",
DataRowVersion. Current, intStatus);

// create the "return value" parameter

//OleDbParameter paramReturn = new OleDbParameter( "RETURN_VAL UE",
OleDbType.Integ er, 4, ParameterDirect ion.ReturnValue , false, 0, 0, "",
DataRowVersion. Current, "");

OleDbParameter paramReturn = new OleDbParameter( "RETURN_VAL UE",
OleDbType.Integ er, 4);

paramReturn.Dir ection = ParameterDirect ion.ReturnValue ;

oleCommand.Para meters.Add(para mJobItemID);

oleCommand.Para meters.Add(para mStatus);

oleCommand.Para meters.Add(para mReturn);
oleCommand.Exec uteNonQuery();

Console.WriteLi ne("RETURN_VALU E:" + paramReturn.Val ue);
}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}
Nov 15 '05 #3
i found the problem.

just add RETURN_VALUE before others.
"Mullin Yu" <mu*******@ctil .com> wrote in message
news:uY******** ******@tk2msftn gp13.phx.gbl...
I got error:
Procedure or function UpdateJobItemSt atus has too many arguments specified.
try

{

long lngJobItemID = 200401130000140 01;

int intStatus = 4;

ICWLogon.clsICL ogon oLogon = new ICWLogon.clsICL ogonClass();

string rtn = oLogon.Logon("e dms3", "edms3", "",
ICWLogon.eLogon Mode.eOnlineMod e);

Console.WriteLi ne("rtn: " + rtn);

string dbstring = oLogon.Database Conn.Connection String + ";database= " +
oLogon.Database Conn.DefaultDat abase;

// set up connection information

OleDbConnection oleConn = new OleDbConnection (dbstring);

oleConn.Open();

OleDbCommand oleCommand = new OleDbCommand();

oleCommand.Comm andText = "UpdateJobItemS tatus";

oleCommand.Comm andType = CommandType.Sto redProcedure;

oleCommand.Conn ection = oleConn;

// create the input parameter

OleDbParameter paramJobItemID = new OleDbParameter( "@JobItemID ",
OleDbType.BigIn t, 8, ParameterDirect ion.Input, false, 0, 0, "JobItemID" ,
DataRowVersion. Current, lngJobItemID);

OleDbParameter paramStatus = new OleDbParameter( "@Status",
OleDbType.Integ er, 4, ParameterDirect ion.Input, false, 0, 0, "Status",
DataRowVersion. Current, intStatus);

// create the "return value" parameter

//OleDbParameter paramReturn = new OleDbParameter( "RETURN_VAL UE",
OleDbType.Integ er, 4, ParameterDirect ion.ReturnValue , false, 0, 0, "",
DataRowVersion. Current, "");

OleDbParameter paramReturn = new OleDbParameter( "RETURN_VAL UE",
OleDbType.Integ er, 4);

paramReturn.Dir ection = ParameterDirect ion.ReturnValue ;

oleCommand.Para meters.Add(para mJobItemID);

oleCommand.Para meters.Add(para mStatus);

oleCommand.Para meters.Add(para mReturn);
oleCommand.Exec uteNonQuery();

Console.WriteLi ne("RETURN_VALU E:" + paramReturn.Val ue);
}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}

Nov 15 '05 #4

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

Similar topics

7
5772
by: Shaine Fisher | last post by:
I have had a look around but I'm either not finding or not seeing the answer to this, what i want to do is reurn the results as an array, or some other worldly useful format that flash mx2004 can read. But when I did thiss I was told datasets were the way to go, but needs an array, prefer typed as were changing it. Here is the current code: (shortened for readability) public class WebService1{
0
1940
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my DataSet, it is trimming the trailing spaces. Anybody know why? Here is my code: System.Data.OleDb.OleDbConnection connection = null;
6
6086
by: Grant | last post by:
I am connecting to an access database using a datareader in C#. I get results when I run a certain query from Access but when I run it from Code it does not retrieve any results. I have put a stop point after the string is created and it is correct. Its an inner join query so I was wandering whether that is too complicated for a datareader to execute, or if Im missing something else here? Heres what Im doing in code: ...
6
5668
by: KathyB | last post by:
Hi, On Page Load (if not postback), the user selects a choice from dropdownlist1. On SelectedItemChanged for dropdownlist1, dropdownlist2 is populated and the user selects an item. I cannot find a combination where I can RETAIN both values during postback...if I put if not posback on the change event of
3
11741
by: Reney | last post by:
I am using Access Database in my program. The column in the table that I am going to use has date/time value with Medium Time selected. (HH:mm). The program is recording a clock in time to this field, which is the time when the entry is made. If you check the database, it shows the correct time in the correct format. But when you are calling it with a dataset and showing with a datagrid, it doesn't show the time value but it always shows...
8
2163
by: Peter | last post by:
Hi, there I have created an stored procedure using the DDL below for my MS Access Database and no error occurs. Also it can create an stored procedure if I changed the parameter from "" to ""@zSampleName". OleDbcmd.CommandText = _ "CREATE PROCEDURE udpGetSampleIDByName" & vbCrLf & _ "( VarChar(64))" & vbCrLf & _ "AS" & vbCrLf & _
0
1806
by: fniles | last post by:
I am using VB.Net 2003 and MS Access database. Sometimes when I open the database, I got the error "Unspecified error" The application validate users, when it validates users, it reads from a table in the database. I use connection pooling by opening the database in Form_Load, then everytime somebody comes in, I open the database and reads from it to validate the user. I then close the database. How can I fix this "Unspecified error" ?...
3
5648
by: Nathan Sokalski | last post by:
When I attempt to access a Microsoft Access database from my website, I recieve the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the...
10
2353
by: Mikesinfo | last post by:
Hi everyone, Hopefully this is the right forum to use. I am programming in C# and I've been racking my brain and searching for the right answer to extract my information according to after a certain input date. the problem is that when I hard-code the numeric date, there is no problem at all and all requested information is displayed correctly. But when I try to pass the variable (parameter) as an integer as in the code that follows, the...
0
9793
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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
10777
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
10494
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
10534
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
10208
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
5620
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3964
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
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.