473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Static database objects

Hello,

I have a number of instances in which I need to grab a single value
from a table based on an index. Usually that table is an attached
table. I know Access provides the DLookup function to do this kind of
thing but I've been fooling around with functions like the abbreviated
one below to do this more efficiently:

Function GetVal(lngIndexID as long) as Variant

Static db as Database
Static rst as RecordSet

' GetRecordSet() returns a table-type recordset in rst and
' a database reference in db for the table named in the first
' argument regardless of whether it is attached or resides
' in the current database.
If rst Is Nothing Then
Call GetRecordSet("tblMyTable", db, rst)
rst.Index = "PrimaryKey"
End If

rst.Seek "=", lngIndexID
GetVal = rst.Fields("MyField")

End Function

My question is if anyone has used this kind of function (using static
db and recordset objects) in a production system and if they've
experienced any negative consequences. For example, I have no idea
how much it costs in terms of memory to maintain static references to
a number of database objects and/or recordset objects or if that
amount of memory changes depending on the characteristics of the
objects themselves, i.e., number of tables, number of fields, etc.
Are there instances where this kind of function ceased to work for
you? It seems to work well in my limited testing at least. Any
comments greatly appreciated. Thanks.

Bruce
Nov 12 '05 #1
3 3068
br***@aristotle.net (Bruce) wrote in news:d3b3c84d.0311050956.127731d0
@posting.google.com:
Hello,

I have a number of instances in which I need to grab a single value
from a table based on an index. Usually that table is an attached
table. I know Access provides the DLookup function to do this kind of
thing but I've been fooling around with functions like the abbreviated
one below to do this more efficiently:

Function GetVal(lngIndexID as long) as Variant

Static db as Database
Static rst as RecordSet

' GetRecordSet() returns a table-type recordset in rst and
' a database reference in db for the table named in the first
' argument regardless of whether it is attached or resides
' in the current database.
If rst Is Nothing Then
Call GetRecordSet("tblMyTable", db, rst)
rst.Index = "PrimaryKey"
End If

rst.Seek "=", lngIndexID
GetVal = rst.Fields("MyField")

End Function

My question is if anyone has used this kind of function (using static
db and recordset objects) in a production system and if they've
experienced any negative consequences.


I have used something like this ... as below:

Dim rLogin As ADODB.Recordset

Public Property Get Login() As ADODB.Recordset
Set Login = rLogin
End Property

This code is part of my login form's module. Througout the application,
forms check this recordset with something like

With Form_frmLogin
User = .Login.Collect(0)
End With

and modify what they show and allow according to what they find. I've
strayed from Access security in this way because my app is part ADP and
part HTML-ASP.
It's not been a problem yet.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #2
Trevor Best did this kind of stuff a long time ago. TLookup etc... I
*think* it's on AccessWeb www.mvps.org/access
Nov 12 '05 #3
It's probably a better practice to put the info into a global variable
or object and not stay connected to any database/table. The best
designs I've seen revolve around transaction based interactions with a
database - this would allow for easy migration to a web front end and
the same db and quereies

br***@aristotle.net (Bruce) wrote in message news:<d3**************************@posting.google. com>...
Hello,

I have a number of instances in which I need to grab a single value
from a table based on an index. Usually that table is an attached
table. I know Access provides the DLookup function to do this kind of
thing but I've been fooling around with functions like the abbreviated
one below to do this more efficiently:

Function GetVal(lngIndexID as long) as Variant

Static db as Database
Static rst as RecordSet

' GetRecordSet() returns a table-type recordset in rst and
' a database reference in db for the table named in the first
' argument regardless of whether it is attached or resides
' in the current database.
If rst Is Nothing Then
Call GetRecordSet("tblMyTable", db, rst)
rst.Index = "PrimaryKey"
End If

rst.Seek "=", lngIndexID
GetVal = rst.Fields("MyField")

End Function

My question is if anyone has used this kind of function (using static
db and recordset objects) in a production system and if they've
experienced any negative consequences. For example, I have no idea
how much it costs in terms of memory to maintain static references to
a number of database objects and/or recordset objects or if that
amount of memory changes depending on the characteristics of the
objects themselves, i.e., number of tables, number of fields, etc.
Are there instances where this kind of function ceased to work for
you? It seems to work well in my limited testing at least. Any
comments greatly appreciated. Thanks.

Bruce

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ren? Paw Christensen | last post by:
Hi. Considering the following code, I want this call: Something.Method(); To return "Something". public class BaseClass { public static string Method() {
10
by: Paschalis Pagonidis | last post by:
Hi, I have a class which all its attributes, properties and methods are static. However, I want a method to return an object that should be non-static. Is that possible?
2
by: Claire | last post by:
If I need to create thousands of objects of the same type, is it more economical (memory wise) to use static member functions where possible? How about virtual ones?
9
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database...
4
by: Rick | last post by:
Hello, Below I create a static instance of an object, works well. public static BasicCounter GlobalCounter = new BasicCounter("GlobalCounter"); private void Page_Load(object sender,...
2
by: blue | last post by:
We have an abstract class with all static methods. It makes sense to have it static because there are no member variables and the constructor is empty. Some of the methods update the SQL Server...
15
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
2
by: mark4asp | last post by:
Q: Initialising and updating a class with only static members & database dependency I have a class with the following members: public static List<ACISACIS_List; static AssetClass() { //...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.