By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

Calling Classes by Recordset

P: n/a
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!
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
..
"Amanda" <de*****@hotmail.com> wrote in message
news:55**************************@posting.google.c om...
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!

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.