Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42740

VS 2010 Passing Connection Object To All My Custom Objects

$
0
0
I have a general "Best Practices" question...

What is the best way to pass the database connection string/object to custom objects?

They way I've been doing it is that I have the connection object as a parameter of my save function...

Code:

Public Class Cars

    Public Function Save(con as oledbConnection) as boolean
        .....
    End Function

End Class

So when I make the save call i do...

Code:


    obj.Save(g_odb.dbConnection)
    '-->g_odb.dbConnection is my connection object

I could not think of a better way to do this and not have the connection string in each one of my custom objects. I want the objects to be as generic as possible so I want to pass in which database to connect too.

Is it better to pass in the connection information when the custom object is created?
Or is there a way to setup my program that the custom object will know where to look to acquire the connection information?

Hopefully it's clear on what I'm looking for...

Does anyone have a "best practice" method of doing what I want?

Viewing all articles
Browse latest Browse all 42740

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>