using params with out.

  • Thread starter Thread starter Ashish
  • Start date Start date
A

Ashish

hi All,

Iam facing a peculiar problem, where i would like to parse the passed
parameters and would like to figure out which ones are marked 'out'. For
example the method signature is

public DataSet SearchItems(string procname, params objects[] values)
{
// call database here
}

and calling code can look like

int count;
DataSet ds = SearchItems("usp_searchme","John","Doe",out count);

In the SearchItems i would like to pass the count as out paramater to
the stored proc and would like to fetch its value back

Any ideas how i could implement this ?

thanks
 
I don't think you can do this with the params syntax; however, if you can
(at the caller) create an object[] to pass in, the method should be able to
update the elements inside the array, and then the caller should be able to
access the updated values (since only the address to the array is really
passed over). Of course, (as always with object[] arguments) this doesn't
really tell you much about the params...

e.g. (note I have left it as "params" to allow simple usage when only
passing values in)

static void Main() {
object[] args = new object[] {"John","Doe",null};
DataSet ds = SearchItems("usp_searchme",args);
int rows = (int) args[2];
}
static DataSet SearchItems(string procname, params object[] values)
{
values[2] = 37;
return null;
}

Marc
 
Ashish,
If the "values" object array contains SqlParameters (or OleDb- whatever you
are using), then you should be able to case each element to an instance of
the SqlParameter class and check its ParameterDirection property.
Peter
 
Any ideas how i could implement this ?

Very easily: Give methods with different signatures, different names!

What exactly are you gaining by funneling all your data access through
one method?

Why not have a method:

DataSet SearchMe (string firstName, string lastName, out int count);

Now you have no need whatsoever to analysis your parameters. You just
pass them to the stored procedure & get your data back.
 

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

Back
Top