Data Reader and Stored Procedure

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

I am trying to figure out at what point I can read my parm values from a
stored procedure. I know (think) that I can not read the parms until I
have processed al of the records. If I am binding my datareader to a
datagrid, can I then access the parms after the databind? Can I not read
my parms if I am binding to a datagrid?

Thanks in advance for your assistance!!!!!!
 
Hi Jim,

If you are looking to read out Parameters (i.e.
parameters marked OUT in your Stored Proc) you can do
that as soon as ExecuteNonQuery() (or whichever variant
your using) has returned.
The values will be stored in the Parameters properties
which can be index like this sqlCommand1.Parameters
["@MyParamName"].
There is no need to databind at all.

If you are looking for the values retured in your
DataReader you can read those out of the DataReader
directly using:
myReader.GetInt32(0) or myReader.GetString(1) etc..
Where the number is the column number (or ordinal) of the
value you are trying to read.
Again there is no need to databind.

Hope that helps.
Jan
 
Hi Jim,

In addition to what Jan said.
Are you using asp.net application?
Anyway, DataReader is forward only reader.
Thus if it is consumed by some control (databind) you won't be able to
retrieve any data from it as the control probably read all data from it.
Thus, you'll have to read manually from it (as Jan suggested) or read data
from bound control.
 
Thanks Jan for your reply, but it does not seem to work for me.

I and executing a proc which should return "rows", If it does not return
rows, I set the @RETURN_VALUE to -2 and set the @msg parameter to "Customer
Not Found". When I do the command "dim dr as SQLDataReader
cmd.ExecuteDataReader" and follow this with an immediate inquiry as to the
parms, nothing is returned into the @msg parm. I have run this same stored
procedure in debug mode in the Query Analyzer and it returns the "Customer
Not Found" message, but when I not execute it within the VB.Net code,
nothing is returned, in I inquire immediately after the
cmd.ExecuteDataReader or if I do the bind and then check those values.

So if the can be returned, I am unable to find a way to get them...
 
Back
Top