473,545 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP class help - For database & form with 120 fields

Dan
(Using Classic ASP & MS Access)

I have a page that has 120 fields on it (mostly checkboxes). I cannot
split this into smaller pages.

So what i want to do is write a class that handles this. in the code it
would be something like:

Set thisForm = new classBigForm

thisForm.valnam e = Request.Form("n ame")
thisForm.val1 = Request.Form("v al1")
thisForm.val2 = Request.Form("v al2")
thisForm.val3 = Request.Form("v al3")
thisForm.xyz = Request.Form("x yz")
.....

Writing the class wasn't too bad. But repeating the same code 120
times, the file got pretty big. Is there a better way to do this
dynamically?

Also in the same respect to the amount of fields, is there an easy way
to compare all of these values, so I can run an sql update only on the
ones i need to?

Apr 21 '06 #1
7 2019

Dan wrote:
(Using Classic ASP & MS Access)

I have a page that has 120 fields on it (mostly checkboxes). I cannot
split this into smaller pages.

So what i want to do is write a class that handles this. in the code it
would be something like:

Set thisForm = new classBigForm

thisForm.valnam e = Request.Form("n ame")
thisForm.val1 = Request.Form("v al1")
thisForm.val2 = Request.Form("v al2")
thisForm.val3 = Request.Form("v al3")
thisForm.xyz = Request.Form("x yz")
....

Writing the class wasn't too bad. But repeating the same code 120
times, the file got pretty big. Is there a better way to do this
dynamically?

Also in the same respect to the amount of fields, is there an easy way
to compare all of these values, so I can run an sql update only on the
ones i need to?


You'll need to provide a bit more information on the form fields. Are
they all Yes/No options? Or are you providing users with a series of
related options, or groups of related options? How do they map to
database fields?

Also, what is the purpose of your class? Outputting the checkboxes in
html? Data Inserts, updates, deletes?

--
Mike Brind

Apr 21 '06 #2
Dan
Yeah, i was trying to keep it short. I figured that any longer, then
people wont read it. :)

The database has four tables. I'll pretend that the data were working
with are "items".

1. items - about 10 fields. holds info like "itemID".

2. itemProperties - about 40 fields.
itemID (to match with that of the 'items' table), - AUTO NUMBER
3 text fields, and everything else is a yes/no

3. itemMorePropert ies - about 40 fields
itemID (to match with that of the 'items' table)
5 text, and everything else "yes/no"

4. another table also related to items. assorted data types
The class acts as a container. For a any item it can hold all of it's
data.

(in the most common scenario)
the script creates a new class and populates it from the database. At
this point we take any http posts, and compares with the value in the
class. If it is different, then it is stored in the class, and the
class puts in in the db.

Apr 21 '06 #3
Dan wrote:
(Using Classic ASP & MS Access)

I have a page that has 120 fields on it (mostly checkboxes). I cannot
split this into smaller pages.

So what i want to do is write a class that handles this. in the code
it would be something like:

Set thisForm = new classBigForm

thisForm.valnam e = Request.Form("n ame")
thisForm.val1 = Request.Form("v al1")
thisForm.val2 = Request.Form("v al2")
thisForm.val3 = Request.Form("v al3")
thisForm.xyz = Request.Form("x yz")
....

Writing the class wasn't too bad. But repeating the same code 120
times, the file got pretty big. Is there a better way to do this
dynamically?
One thing that may help is to use an array or dictionary object to store all
these boolean values, instead of using indifidual properties. (it sounds as
if your database structure would benefit from the same thinking). Are they
really named val1,...,valx? Or do they have real names with/without numbers?
if the former, just use an array. For refreshing the array values from the
Request object, you would do something like:

function RefreshFromRequ est()
dim i, req
'First, set all the booleans to False
for i = 0 to ubound(arBools)
arBools(i)=fals e
next
'Then, set the ones that appear in Request to True
Set req=Request.For m
for i = 0 to ubound(arBools)
if len(req("val" & i)) > 0 then arBools(i)=true
next
end function

if the latter, you will need to persist the field names in order to avoid
going to the database every time you need to use the dictionary. You could
do this in a file or in in an xml document kept in Application (don't even
think about storing a Dictionary object in Application or Session). Let's
say you do the xml in Application route. You would do something like this in
global.asa (untested - I did not refer to the documentation so there may be
minor syntax errors - you can find te documentation at
http://msdn.microsoft.com/library):

sub application_ons tart()
dim fld, xmldoc, root, node
set xmldoc=createob ject("msxml2.Fr eeThreadedDomDo cument")
set root=xmldoc.cre ateelement("fie lds")
set xmldoc.document element=root
'connect to the database and open a recordset on the first table
'Use a "where 1=2" clause to prevent records from being retrieved -
'we only want the field names at this point
'then
for each fld in rs.Fields
set node=xmldoc.cre ateelement("fie ld")
node.setattribu te "fieldname",fld .name
root.appendchil d node
next
'do the same for the subsequent tables - again, I would reconsider
'the database design ...
'then:
Set Application("Fi eldNamesXML") = xmldoc
end sub

This will allow you to do this in your class's init sub:

set dicBools=create object("scripti ng.dictionary")
set xmldoc=Applicat ion("FieldNames XML")
nodes=xmldocs.s electNodes("fie lds/field")
for each node in nodes
dicBools.Add node.getattribu te("fieldname") ,false
next
set BoolVals = dicBools

To refresh it from Request:
dim dicBools, req,fieldname
set dicBools = BoolVals
'since it's already initialized in the init sub, no need to set
'all the values to false

Set req=Request.For m
for each fieldname in dicBools
dicBools(fieldn ame)=req(fieldn ame)
next

Also in the same respect to the amount of fields, is there an easy way
to compare all of these values, so I can run an sql update only on the
ones i need to?


I would not consider doing dynamic sql for this. Just create a single
parameterized statement or saved query and pass all the values to it. You
are not going to save much processing time by only updating the ones that
have changed.

Here are some links explaining this approach:
Saved parameter queries:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl

Using a Command object to pass values to string containing parameter
markers:
http://groups-beta.google.com/group/...e36562fee7804e
I will reply to your follow-up with a suggestion for your database design.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 22 '06 #4
Dan wrote:
Yeah, i was trying to keep it short. I figured that any longer, then
people wont read it. :)

The database has four tables. I'll pretend that the data were working
with are "items".

1. items - about 10 fields. holds info like "itemID".

2. itemProperties - about 40 fields.
itemID (to match with that of the 'items' table), - AUTO NUMBER
3 text fields, and everything else is a yes/no

3. itemMorePropert ies - about 40 fields
itemID (to match with that of the 'items' table)
5 text, and everything else "yes/no"

4. another table also related to items. assorted data types
The class acts as a container. For a any item it can hold all of it's
data.

(in the most common scenario)
the script creates a new class and populates it from the database. At
this point we take any http posts, and compares with the value in the
class. If it is different, then it is stored in the class, and the
class puts in in the db.


The flaw with this design is that any time you need to add a new propery,
you have to modify the database structure, as well as all the code that
accesses this data. A better design would be:

boolPropertyNam es
boolName - Text, PK -
used to control names used in BoolPropertyNam es

itemBoolPropert ies:
itemID
boolName - Text containing the name of the property
foreign key to BoolPropertyNam es table
boolValue - Yes/No


This will allow you to use
Select boolName from BoolPropertyNam es

to get the boolean property names.

To add a new property, just add a record to boolPropertyNam es (You should
probably strictly control the names that get entered here - I would not
allow users to create properties - that could lead to chaos). Nothing else
needs to change.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 22 '06 #5
Bob Barrows [MVP] wrote:
if the latter, you will need to persist the field names in order to
avoid going to the database every time you need to use the dictionary. You
could do this in a file or in in an xml document kept in Application
(don't
even think about storing a Dictionary object in Application or Session).
Let's say you do the xml in Application route.


BTW, I am not married to the use of the Dictionary object. By adding an
attribute to the xml document, you could use the xml document to store your
values, instead of incurring the overhead of the dictionary object.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 22 '06 #6
Bob Barrows [MVP] wrote:

To add a new property, just add a record to boolPropertyNam es (You
should probably strictly control the names that get entered here - I
would not allow users to create properties - that could lead to
chaos). Nothing else needs to change.

If storing the names in Application, you will need to either restart your
application or create a page to refresh then names in the application object
whenever you add a new property name to this table.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 22 '06 #7
Dan
Thanks for all the advice. I think i want to go somewhere where bob
was mentioning, but im still not exactly sure.

As for the field names they are not all 'val1', 'val2'.. I believe all
of them are 3 letters long and all letters.

Here is a little more info on the class, and how i want to use it.

'1. grab the data and put it into a class
set existForm as new BigForm
existForm.formI D = Request.Form("f ormID")
existForm.Popul ateFromDB
' this would select * from...
'2.
set newForm as new BigForm
' copy all the values from existForm to newForm.
'3. I would have an array that lists all the fields.
' this part in not sure what the proper syntax would be. this would be
a function in the class called, populateFromHTT P

For i = 0 to ubound(aryTable Two)
newForm.i = Request.Form(i)
Next
'4. Finally we update the database, again using the array for the
field names.

For i = 0 to ubound(aryTable Two)
If existForm.i != newForm.i Then
' There has been a change.
'strSQL = strSQL & "UPDATE tableTwo Set " & i & " = newform.i &
" WHERE formID = " & newform.formid & ";"
End IF
Next

I think this method should work for the majority or the items. A few
things will need some special handling but i can work that out. Does
anybody know what the proper syntax for the above idea would be?

Apr 23 '06 #8

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

Similar topics

4
1855
by: Perttu Pulkkinen | last post by:
Hi all php freaks! Do you think this kind of "property class" is useful or not? I have bee bored to the way I've been coding earlier. because: - often i have database-oriented classes like product, category, news etc. - often i have fex. load, request, insert, update and delete functions for them - often problems are the same ones: -...
1
2580
by: leegold2 | last post by:
The subject title is a sedgeway into my question that may slightly of topic but I've asked many sources and don't have an answer yet so I ask it here. I have a text fields of html marked up content which I render via php. Looking at the rendered html page in a text editor I see that ampersands all appear as & When I select the field via...
1
2577
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update...
3
2175
by: rockoyster | last post by:
Not sure if this is entirely a CSS issue but I have defined the class below in CSS. If I am stretching the friendship then I apologise in advance. I am trying to write a javascript script to check that all required fields in a form are entered. The idea was to give all required input fields a class of say "mandatory" and then check...
42
4902
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
9
3335
by: Richard Brown | last post by:
Can anyone give me a good argument one way or another? I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These fields are all normalized into a seperate database table from the client and destination tables. My question is, which is better to create, a User...
16
4231
by: Richard Brown | last post by:
Ok, now I am truely going nuts... probably why I didn't use the Class Builder in VB6 extensively. But, being the 'proper programmer' that I should, I'm trying to bite the bullet and build classes for each of my 'entities' that operate within the program, ie, passenger, vehicle, etc. Then seperate UI classes that link to these. (Partially,...
4
1561
by: cover | last post by:
I have two distinctively different pieces of equipment that I'm trying to build a database for, each having 20 inputs which makes my mysql table 40 fields wide. Form one is for 'shakers' and form two is for 'conveyors'. About the only thing they will have in common is that they both share 'motorsize' and they both share 'bearing' although...
1
2355
by: Brit | last post by:
I have an ASP file that retrieves names from an Access database for 4 different categories of membership, which the visitor to the page selects (corporate, institutional, regular, or student). The DNS name is "cati", the names are specified in the "Last_names" field, and the categories are in the "categories" field. l want the results sorted in...
0
7465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.