Calling Classes by Recordset

  • Thread starter Thread starter Amanda
  • Start date Start date
A

Amanda

Let me see if I can explain this correctly.

In VB.NET, I want to call classes based on a recordset I get back from
a SQL Server database.

Basically, I have a value sending in a table called
cls.CallFunction(strParameter).

In VB.NET cls.CallFunction is a class and a function in my code.

How do I convert my recordset value (cls.CallFunction (strParameter))
into a string value that will actually call the function.

Gosh, I hope that makes sense, and I didn't sound like a complete
idiot

Please respond back to this post :)

Thanks!
 
here's the idea:
(Note: watch for typos and syntax - I'm directly typing this in this message
so you'll have to double check syntax, etc etc)

first - trim the string to get the class name, method name and method
parameter(s) seperated out.
Dim str As String = "cls.CallFunction(strParameter)"
Dim ClassName As String = str.SubString(1, str.IndexOf(".")-1)
Dim MethodName As String = _
str.SubString(str.IndexOf(".")+1, str.IndexOf("(") - str.IndexOf("."))
Dim Parameter As String = _
str.SubString(str.IndexOf("(")+1, str.Index(")") - str.Index("("))
(you'll have to do a little more work if you have more than one parameter)

Then use Type.GetType( ) method to get the type object for your class (read
up the documentation on Type.GetType( ) to make sure you get it right -
there are several rules on how to pass in the class name; for instance, you
need to pass in your application name, namespace name, etc etc)
Something like:

Dim myType As Type = Type.GetType(myAppName & myNameSpace & ClassName)

Then use the InvokeMember function of the type class to execute the method.
Something like:

Dim args( ) As Object = {strParameter}
myType.InvokeMember("CallFunction", BindingFlags.Public Or _
BindingFlags.InvokeMethod, Nothing, Nothing, args)
(make sure you get the BindingFlags right otherwise it'll blowup here.
lookup the various values for BindingFlags and use the ones that match the
criteria for your method)

Well - thats just about the idea on how to do this.

hope that helps..
Imran
..
 

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