Solved

stored procedure as class property

Posted on 2006-07-09
4
208 Views
Last Modified: 2010-04-23
I'm trying to build a VB.Net class.
I'd like to show a list of stored procedure read from a database as a property value

example
class name: myclass
property name: storedprocedurelist

myclass.storedprocedurelist.(here I want a list of my stored procedure read from a database)

hoping to be clear
0
Comment
Question by:xtremereality
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17068619
If you want a list only then you can expose a property returning a string array. Like

Public MyClass
  Private m_StoredProcedures as String() 'private variable to hold property value

....

  Public Property StoredProcedureList() As String()
    Get
      Return m_StoredProcedures
    End Get
    Set(ByVal value As String())
      m_StoredProcedures = value
    End Set
  End Property

....

End Class

But if you want to have a more object-orientated class witch exposes a collection of objects with their own properties then you have to define a class for a single strored procedure, a class that represents a collection of you stored procedures and add that collection class to your MyClass class.

If you need any further details please let me know
0
 

Author Comment

by:xtremereality
ID: 17068777
before my question I tryed something like this:
---------------------------------------------------------------------------------------------------------
Public Class Class1
    Private m_Storedprocedures As Collection = New Collection

    Public ReadOnly Property StoredProcedureList() As Collection
        Get
            Return Populate()
        End Get
    End Property

    Public Function Populate() As Collection
        m_Storedprocedures.Add("sp_sample1")
        m_Storedprocedures.Add("sp_sample2")

        Return m_Storedprocedures
    End Function
End Class
---------------------------------------------------------------------------------------------------------
DRIVER CODE IN ASP.NET PAGE:

Dim oTest As Class1
oTest = New Class1
Response.Write(oTest.StoredProcedureList.Item(1))

But I won't this
---------------------------------------------------------------------------------------------------------

My goal is to have a class that expose me a list of all stored procedure stored into a database.
I arranged an image to show the result I want to obtain at:

http://www.ccna.it/example.jpg

<img src="http://www.ccna.it/example.jpg">

to better explain my goal
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17068925
Well, I have never did some kind of stuff before and couldn't find any samples, but I think if you want to have something like your picture shows then your class has to have "hardcoded" these members. But this can make your code to become "buggy" or something like "environment-depending" in case if database's structure changes (e.g. some stored procedures are added or deleted).

As I mentioned earlier I'd suggest you to use ArrayList. The link below has some brief tutorials on how to use arraylist objects:
http://abstractvb.com/code.asp?A=1030
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17069059
You can define a TypeConverter for the property to retrieve values.

Make a type converter in Visual Basic .NET
http://www.vb-helper.com/howto_net_type_converter.html

Bob
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question