473,473 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Constants for DB Fields in Front End a good idea?

Was wondering if anyone uses constants for field names coming from the
db stored procedure whihc return the query result? If the field name in
the DB changes, it surely helps but the work around I usually use is
the alias in the query? Any suggestions or idea?

Thanks.
-OMD

Feb 10 '06 #1
4 1460
I store database procedure names, parameter names, and result set
column names in a mapping file. I keep a separate mapping file for
each table. I also create a data factory for each table.

See an example of my mapping files here:
http://www.xquisoft.com/xqsdn/docume...taFactory.html

Then I can use intellisense in the factory class to use the mapped
entities. The code example above uses an open source component that
you can find here:
http://sourceforge.net/projects/xqs-data/

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Feb 10 '06 #2
OMD,

Actually, I prefer to use a typed dataset if possible, so that I have
compiler support for fields on the table.

If your design doesn't warrant the use of a typed dataset for the result
set, then I would go with the constants. With constants, if you make a
change in the SP in the data it returns, you just change the constant in
your code and recompile.

With typed data sets, you have to actually refactor your code everywhere
so that you use the new field name, since the property exposed will be with
the new field name (once you regenerate your typed data set in response to
the change in the SP).

It's a trade off, really, as you get the safety of the compiler with
typed data sets, whereas with a constant, if the constant is wrong, then you
can get an error at run time.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"OldMacDonald" <ra*******@softhome.net> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Was wondering if anyone uses constants for field names coming from the
db stored procedure whihc return the query result? If the field name in
the DB changes, it surely helps but the work around I usually use is
the alias in the query? Any suggestions or idea?

Thanks.
-OMD

Feb 10 '06 #3
Thanks Nickolas & Mike. I am using XSD's in my project but refactoring
is a bit of pain. What would be the overhead of using constants or
IDataFactory Interface on the performance compared to the hard coding...

Feb 10 '06 #4
Datasets (typed or not) take more memory. I can't give a solid number
because I have not run extended tests. However, it's obvious. Just
look at all the data that a dataset contains. First it contains all
the data you want, and this is good. Custom entities also contain that
data. The overhead comes with:
1) all the schema (table name, column names, column types, etc...)
2) multiple versions of the data (Current, Original, Proposed).

The architecture I proposed was designed partially for compiler and
intellisense support. The other layers of your application have full
intellisense support on business and data layer classes that interact
with the database. When a database entity changes, you only have one
line of code to update. If you forget, you get a runtime error that
explains exactly which field name was "missing" and on what procedure
or table.

As Nicholas said, you have multiple changes to make through your
application when the xsd regenerates the typed dataset. You now have
to change code in every class and method in your solution that uses
that dataset. Do you bind that dataset to the ui? Do you auto-generate
columns, or like most people do you like to rename the database columns
to a friendly user interface name. IE. "FirstName" to "First Name".
Then when you create a bound column, you are not using intellisense
everywhere. Instead you are typing a string value, which is not
checked until runtime.

Example of the invalid dataField in my aspx page:
<asp:BoundColumn Visible="False" DataField="FirstNM" HeaderText="First
Name"></asp:BoundColumn>

Runtime error:
"A field or property with the name 'FirstNM' was not found on the
selected datasource."

Silly me, the DBA renamed FirstNM to FirstName.

I have not used a typed dataset, anyone know if non-autogenerated
columns behave any differently?

When I bind custom entities to a grid, I use the same BoundColumns in
the aspx file. The difference is that the property name on the class
does not change when the database column changes, the data layer just
maps the new database entitiy name to the same old class property name.
Therefore the grid does not need to be changed. After all I always
want the same name, FirstName for my property. As a UI developer, I
could care less if the DBA decides to rename column FName to FirstName
to First_Name to FirstNM.

If you were starting from scratch, I would recommend the same solution
I gave above. But if you have alot of code written already, it may be
best to stick with what you have. That is what I am doing with the
example BoundColumn above. I wasn't given enough time for a rewrite.
From a practical point of view, you can't just refactor your entire

application everytime you find a different way to do something. You
can use new ideas in your next project.

Michael Lang
XQuiSoft LLC
http://www.xquisoft.com/

Feb 14 '06 #5

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

Similar topics

0
by: William Ryan | last post by:
WebConfig is made for storing such constants but there are other methods as well. You can create a Module in VB.NET or a class with Static Members in C# and query your DB at the onset and...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
1
by: SerGioGio | last post by:
Hello, I want to build a ".lib" library where I will have some constants. The constants are not only int, char, but also struct constants. How do I declare / implement these struct constants? I...
7
by: Iain Mcleod | last post by:
Hi This must be an often encountered problem. I want to declare an abstract class or an interface with nothing but several static constants so that I can use polymorphism when I call each of them...
3
by: rdemyan via AccessMonster.com | last post by:
I'm thinking about providing a relatively easy method for users to restore the front end from a backup. The purpose is to allow for restoring if the front end becomes corrupt. Here are some...
34
by: newsposter0123 | last post by:
The code block below initialized a r/w variable (usually .bss) to the value of pi. One, of many, problem is any linked compilation unit may change the global variable. Adjusting // rodata const...
3
by: rdemyan via AccessMonster.com | last post by:
One of my users had a corrupt front end that wouldn't open. My app is launched using a launching application (logon app). The logon app has a button for downloading a "fresh" copy of the front...
17
by: Neil Cerutti | last post by:
The Glk API (which I'm implementing in native Python code) defines 120 or so constants that users must use. The constants already have fairly long names, e.g., gestalt_Version, evtype_Timer,...
12
by: Gordon | last post by:
I want to provide a set of static functions in a superclass that work with class constants defined in a decendant of that class. Unfortunately I've run into a snag with this idea. Example: ...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.