473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stored Procedures that return both output parameters and table results

6 New Member
I'm a newbie to C# development and as a whole, my department has been trying to come over from the VB6 realm. In VB6, I use calls to stored procedures on SQL Servers to return any combination of output. I've learned how to return a data set and output parameters seperately, but need to learn how to get the data on the same round-trip call to the stored procedure.

I can't have it execute the command for a result set, then execute the command again to get the output parameter because database tables are normally updated with each call to the stored procedure. One example is getting a table of information and at the same time, returning a new serial number that the stored procedure generated and logged. The table data is related to that serial number.

I can't afford to rewrite all the stored procedures and also add network bandwidth by making additional calls to get the same information I'm used to getting in the same round-trip call to the database server.

Any help or references would be greatly appreciated. My searches only yield one or the other.
Jun 3 '10 #1

✓ answered by Plater

I think you would just be able to combine them?
For example:
Expand|Select|Wrap|Line Numbers
  1. //this procedure returns 4 tables and sets @OutTest to a value
  2. SqlCommand sc = new SqlCommand("GetShippingResultsForDate", dbcon);
  3. sc.CommandType = CommandType.StoredProcedure;
  4.  
  5. sc.Parameters.AddWithValue("@WhatDay", WhatDay);
  6. sc.Parameters.Add("@OutTest", SqlDbType.Int);
  7. sc.Parameters["@OutTest"].Direction = ParameterDirection.Output;
  8.  
  9. SqlDataAdapter dba = new SqlDataAdapter(sc);
  10. dba.Fill(retval);
  11. object o=sc.Parameters["@OutTest"].Value;
  12. //o is now an int containing the value I set in my stored procedure
  13.  

1 7834
Plater
7,872 Recognized Expert Expert
I think you would just be able to combine them?
For example:
Expand|Select|Wrap|Line Numbers
  1. //this procedure returns 4 tables and sets @OutTest to a value
  2. SqlCommand sc = new SqlCommand("GetShippingResultsForDate", dbcon);
  3. sc.CommandType = CommandType.StoredProcedure;
  4.  
  5. sc.Parameters.AddWithValue("@WhatDay", WhatDay);
  6. sc.Parameters.Add("@OutTest", SqlDbType.Int);
  7. sc.Parameters["@OutTest"].Direction = ParameterDirection.Output;
  8.  
  9. SqlDataAdapter dba = new SqlDataAdapter(sc);
  10. dba.Fill(retval);
  11. object o=sc.Parameters["@OutTest"].Value;
  12. //o is now an int containing the value I set in my stored procedure
  13.  
Jun 3 '10 #2

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

Similar topics

5
by: Steve Holden | last post by:
Has anyone, with any driver whatsoever, managed to retrieve output parameters from a SQL Server stored procedure? I've just been rather embarrassed to find out it's not as easy as it might seem,...
7
by: JT | last post by:
how can i see a stored procedures return value in ASP??
2
by: Lepa | last post by:
Hi I'm trying to make this to work and need help Here my SP and I'm building sql with output param. Alter PROCEDURE lpsadmin_getSBWReorderDollars ( @out decimal(10,2) output, @sType...
1
by: zlatko | last post by:
I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter...
1
by: tdlogger | last post by:
Help! I’m running ado.net using sql7 with service pack 4. I’m trying to use stored procedures. When I try passing varchar type parameters it comes back with 0 transactions. If I pass int...
3
by: Zlatko | last post by:
A question concerning Access Project with SQL Server: I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are...
1
by: evan.lavidor | last post by:
Hi all, Forgive me if this topic has been discussed before. I've been doing some searching and have yet to come across the answer I'm looking for. I'm new to PHP, and I'm trying to call a...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
1
by: jobs | last post by:
I have a growning list of stored procedures that accept a single string as a parameter. The list and parameters are maintained in a table with two columns. Some of the Stored procedures take...
1
by: ravysters | last post by:
hi... i am using VC++ to connect to my database and i am trying to insert a new row into a table. I am also using the returning statement available in postgres to return a column of the currently...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.