The following code does not operate properly, and neither I nor the three
..Net experts can figure out why. It's a seeming mystery. The code is simple.
A SqlCommand is executed against a stored procedure, then a DataReader is
looped through. After the DataReader is exhausted, I attempt to read some
output parameters from the SqlCommand. However, both the output parameters
return <undefined value>.
I understand that one cannot examine the contents of output parameters from
a SqlCommand until after the DataReader is exhausted, but after that, it
should be fine. The Stored Procedure, when run outside the application (from
within Sql Server), returns the correct values, so the fault lies somewhere
here.
(The local methods GetInputParam and GetOutputParam simply build
SqlParameter objects by setting the Direction, Name, Size if necessary, and
data type. They are used all throughout the application and do not pose
problems, unless perhaps some other property needs to be filled.
GetSqlCommand is another local method which creates a SqlCommand object and
assigns the SqlParameter array to it. Same story.)
SqlDataReader vDataReader;
SqlCommand vSqlCommand = null;
SqlParameter[] aryParams = new SqlParameter[3];
aryParams[0] = GetInputParam("@IncludeInactive",
SqlDbType.Bit);
aryParams[1] = GetOutputParam
("@ErrorMessage",SqlDbType.NVarChar, 512);
aryParams[2] = GetOutputParam ("@ReturnValue",
SqlDbType.Int);
vSqlCommand = GetSqlCommand("MyStoredProcedure",
aryParams);
vSqlCommand.Connection.Open();
vDataReader = vSqlCommand.ExecuteReader();
while (vDataReader.Read())
{
// code using parameters from the data set
residing in vDataReader (populating an object)
}
if
(vSqlCommand.Parameters["@ErrorMessage"].Value.ToString()!=""
||(int)vSqlCommand.Parameters["@ReturnValue"].Value == -1 )
{
throw new
CustomException(vSqlCommand.Parameters["@ErrorMessage"].Value.ToString(),
null);
}
}
--
- Jim Owen 2 2647
This would work fine if you use a DataSet instead of the datareader. That is
if its not a big perf implication as Datasets are more heavy and slow than
the data reader.
"Jim Owen" <jk********@comcast.net> wrote in message
news:eD****************@tk2msftngp13.phx.gbl... The following code does not operate properly, and neither I nor the three .Net experts can figure out why. It's a seeming mystery. The code is
simple. A SqlCommand is executed against a stored procedure, then a DataReader is looped through. After the DataReader is exhausted, I attempt to read some output parameters from the SqlCommand. However, both the output parameters return <undefined value>.
I understand that one cannot examine the contents of output parameters
from a SqlCommand until after the DataReader is exhausted, but after that, it should be fine. The Stored Procedure, when run outside the application
(from within Sql Server), returns the correct values, so the fault lies
somewhere here.
(The local methods GetInputParam and GetOutputParam simply build SqlParameter objects by setting the Direction, Name, Size if necessary,
and data type. They are used all throughout the application and do not pose problems, unless perhaps some other property needs to be filled. GetSqlCommand is another local method which creates a SqlCommand object
and assigns the SqlParameter array to it. Same story.)
SqlDataReader vDataReader; SqlCommand vSqlCommand = null;
SqlParameter[] aryParams = new SqlParameter[3]; aryParams[0] = GetInputParam("@IncludeInactive", SqlDbType.Bit); aryParams[1] = GetOutputParam ("@ErrorMessage",SqlDbType.NVarChar, 512); aryParams[2] = GetOutputParam ("@ReturnValue", SqlDbType.Int);
vSqlCommand = GetSqlCommand("MyStoredProcedure", aryParams); vSqlCommand.Connection.Open(); vDataReader = vSqlCommand.ExecuteReader();
while (vDataReader.Read()) { // code using parameters from the data set residing in vDataReader (populating an object) }
if (vSqlCommand.Parameters["@ErrorMessage"].Value.ToString()!=""
||(int)vSqlCommand.Parameters["@ReturnValue"].Value == -1 ) { throw new CustomException(vSqlCommand.Parameters["@ErrorMessage"].Value.ToString(), null); } }
-- - Jim Owen
This would work fine if you use a DataSet instead of the datareader. That is
if its not a big perf implication as Datasets are more heavy and slow than
the data reader.
"Jim Owen" <jk********@comcast.net> wrote in message
news:eD****************@tk2msftngp13.phx.gbl... The following code does not operate properly, and neither I nor the three .Net experts can figure out why. It's a seeming mystery. The code is
simple. A SqlCommand is executed against a stored procedure, then a DataReader is looped through. After the DataReader is exhausted, I attempt to read some output parameters from the SqlCommand. However, both the output parameters return <undefined value>.
I understand that one cannot examine the contents of output parameters
from a SqlCommand until after the DataReader is exhausted, but after that, it should be fine. The Stored Procedure, when run outside the application
(from within Sql Server), returns the correct values, so the fault lies
somewhere here.
(The local methods GetInputParam and GetOutputParam simply build SqlParameter objects by setting the Direction, Name, Size if necessary,
and data type. They are used all throughout the application and do not pose problems, unless perhaps some other property needs to be filled. GetSqlCommand is another local method which creates a SqlCommand object
and assigns the SqlParameter array to it. Same story.)
SqlDataReader vDataReader; SqlCommand vSqlCommand = null;
SqlParameter[] aryParams = new SqlParameter[3]; aryParams[0] = GetInputParam("@IncludeInactive", SqlDbType.Bit); aryParams[1] = GetOutputParam ("@ErrorMessage",SqlDbType.NVarChar, 512); aryParams[2] = GetOutputParam ("@ReturnValue", SqlDbType.Int);
vSqlCommand = GetSqlCommand("MyStoredProcedure", aryParams); vSqlCommand.Connection.Open(); vDataReader = vSqlCommand.ExecuteReader();
while (vDataReader.Read()) { // code using parameters from the data set residing in vDataReader (populating an object) }
if (vSqlCommand.Parameters["@ErrorMessage"].Value.ToString()!=""
||(int)vSqlCommand.Parameters["@ReturnValue"].Value == -1 ) { throw new CustomException(vSqlCommand.Parameters["@ErrorMessage"].Value.ToString(), null); } }
-- - Jim Owen
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bari Allen |
last post by:
I have a Stored procedure in SQL, that works, when tested in SQL, with one
input & several output parameters, as follows:
CREATE PROCEDURE myProcedure
@MyID int
, @First varchar(80) OUTPUT
,...
|
by: Andrew Thompson |
last post by:
I have written a few scripts to parse the
URL arguments and either list them or allow
access to the value of any parameter by name.
<http://www.physci.org/test/003url/index.html>...
|
by: vivienne.netherwood |
last post by:
I am developing an Access Project front end with a SQL server database.
I have written a stored procedure that returns a record set and also a
value via an output parameter.
The procedure is as...
|
by: unique |
last post by:
I have written some programs in c lang yet but today I get confused
with output i get.
I have function educate(..) which i call in main program this way:
J = educate(no_layers, no_neurons,...
|
by: Jim Owen |
last post by:
The following code does not operate properly, and neither I nor the three
..Net experts can figure out why. It's a seeming mystery. The code is simple.
A SqlCommand is executed against a stored...
|
by: Bari Allen |
last post by:
ASP Classic question:
I have a Stored procedure in SQL, that works, when tested in SQL, with one
input & several output parameters, as follows:
CREATE PROCEDURE myProcedure
@MyID int
, @First...
|
by: Garth Wells |
last post by:
Using an example in the Jan 2006 release of the Enterprise Library,
I came up with the code shown below to create a DAL method
for returning several columns of a single row. I place the output...
|
by: Aaron Gray |
last post by:
I put together the following code to get the href's parameters :-
function GetParameters()
{
var arg = new Object();
var href = document.location.href;
if ( href.indexOf( "?") != -1)
{
var...
|
by: gabosom |
last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure.
This is my SP code
CREATE PROCEDURE GetKitchenOrderDetail(
@idService int,
--outPut Variables ...
|
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:
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: 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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: 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,...
| |