Class modules and Recordsets

kocuba

New member
Joined
May 25, 2011
Messages
3
Programming Experience
10+
Currently we have a VB6 application that uses a class module for holding configuration setting for the app(ie nextinvno,nextcustno,etc). This RS and class is kept open the whole time the app is open. I am toying with moving this to a VB.Net app and wondering what is the best way to handle this with the move.

I've included a little bit of our current code as an example...

VB.NET:
Private mvarNextOrderNumber As Long 
Private WithEvents rsConfig As ADODB.Recordset
Public Property Let NextOrderNumber(ByVal vData As Long)
1 rsConfig!nextorderno = vData
End Property
Public Property Get NextOrderNumber() As Long
NextOrderNumber = rsConfig!nextorderno
End Property
Public Sub db_GetConfig()
1 rsConfig.Open "exec vts_GetCONFMAST", connSQL, adOpenDynamic, adLockOptimistic
End Sub
Private Sub Class_Initialize()
1 Set rsConfig = New ADODB.Recordset
End Sub
Public Sub Update()
1 rsConfig.Update
End Sub

Am I going to have change to set the Properties upon startup and also write my own update when something changes or can this remain relatively the same.

TIA
Dave
 
If you're switching to VB.NET then you should switch to ADO.NET for data access. That means opening a connection only when you need to and closing immediately after you're done with it. If you want to store settings in the database then you might consider loading the settings at startup into a single object that gets used throughout the application, saving it back to the database only when some of the data changes. You could also access the database each time you need the data, but that's probably needlessly inefficient.

You might also consider using My.Settings instead of a database. It's not necessarily suitable in all cases but you should look at it first and only look elsewhere if it's not suitable.
 
I'm sorry jmcilhinney I assumed ADO.NET would be required with out stating it. My bad.

So I will need to set every property seperately when the connection is opened and then write seperate update statements for highly used properties and maybe one that does them all? And then call those thru out the application?

Thanks
Dave
 
Back
Top