Passing an object array as ref to function.

C

craigkenisston

Hi,

I'm trying to create a generic function to call stored procedures in a
SQL Server database.
I'm passing the params, values and the direction of the params in
arrays.
The function is working, and I get the output parameters values back in
my the array I sent, however, I'd like to have the values in my
original variables, please see below :


int ID = 0;
string[] Params = {"@USER_USERID", "@USER_ID"};
object[] Directions = {ParameterDirection.Input,
ParameterDirection.Output };
object[] Values = {UserID, ID};
DbSQLServer.ExecuteScalarStored("clsd_GetUserID",
Params, Directions, ref Values);
Console.WriteLine(ID);

at the end of this run the value of ID is zero. But the value of
"Values[1]" (the second) has the returning value of my function.

What I want here, is to be able to fill the original variables
directly, I mean, to put the values in "UserID" and "ID".
I could to this easly with pointers, but without them I feel like hands
tied.

Is this possible ? Or am I just looking for something that can't be
done.

Any recommendation is welcome.
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

Hi,

I'm trying to create a generic function to call stored procedures in a
SQL Server database.
I'm passing the params, values and the direction of the params in
arrays.
The function is working, and I get the output parameters values back in
my the array I sent, however, I'd like to have the values in my
original variables, please see below :
<snip>

You're looking for something that can't be done, unless you resort to
unsafe code, where you can use pointers. I wouldn't recommend it though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top