Using reflection for stored procedures

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 23-May-2006 12:08:50   

Hi,

I have an application that is used by different customers. Customers want to export data according to their own format.

So I have stored procedures to retrieve data like GetAllOrdersCustomer1 and GetAllOrdersCustomer2.

Each procedure has the same parameters, for example CustomerNo and Department.

Now I generate code and get RetrievalProcedures.GetAllOrderCustomer1 and 2, etc.

But I would like to use reflection somehow to call the right generated function, But I can't figure it out, since I can't create an object of RetrievalProcedures and now I don't know how to this this.

Can anyone help me with this?

My Functions look like GetAllOrdersCustomer1(string CustomerNo, string department, ref int returnvalue, DataAccessAdapter adapter)

GetAllOrdersCustomer2(string CustomerNo, string department, ref int returnvalue, DataAccessAdapter adapter)

Thanks in advance,

G.I.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 24-May-2006 03:08:58   

I'm sorry G.I. I'm a little confused what you are trying to do in GetAllOrdersCustomer1 and GetAllOrdersCustomer2 using reflection. Can you post some of the code in those Functions that isn't working? Thanks.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 24-May-2006 08:05:24   

bclubb,

thanks for the interest. I have taken another approach now, using delegates. What I have done is:


public delegate DataTable delExportContracts();

And in my function:


string methodName = "ExsExportContract" + version + companyShort;

BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
ParameterModifier[] modifiers = null;
Type[] types = new Type[0];

MethodInfo minfo = typeof(RetrievalProcedures).GetMethod(methodName, flags, null, types,  modifiers);

delExportContracts exportContracts = (delExportContracts)Delegate.CreateDelegate(typeof(delExportContracts), minfo);

DataTable dt = exportContracts();

This way I build the function name based on the company and version. Now I don't have to write new code each time I add a new stored procedure for another company with llblgen.

I hope this explains a litle what I was trying to achieve. I still have to figure out how to fill the type with parameters, but that'll be ok I think wink

Is there some other solution that is better than this?

Best regards,

G.I.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-May-2006 08:14:27   

You may have used a general SP that accepts an extra parameter, and internally call the other SPs according to that parameter.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 24-May-2006 10:24:09   

Walaa,

If you mean by solving this issue at the SQL Server side, I don't want to do that, since customers have their own version of this SP, specifically made for them.

Or do you mean I should make a general SP, generate code by LLBLGen and change the functions created by adding a parameter in there? If so, how do I make sure the code won't be overridden by a new generate?

And is it possible to to this and only need to change the string procedure name that is passed on to the adapter?

Tia,

G.I.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-May-2006 14:32:52   

Actually I meant solving it at SQL server side.