473,703 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ 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 1467
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.co m

"OldMacDona ld" <ra*******@soft home.net> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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:BoundColum n Visible="False" DataField="Firs tNM" HeaderText="Fir st
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
3573
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 populate these fields there. In one case you change Web.Config when you want to make changes, in the other you change you DB fields. Since ADO.NET is probably how you'll access the data, they are both essentially as dynamic as the other one. ...
6
17156
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 this can be done? I've tried setting the default value of the text fields on the form to be equal to ! using Access' expression
1
1411
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 came up with 3 solutions but I am really satisfied with none of them: 1. use #define This can work with constants int or char*, but not really with structures. If you have
7
9293
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 from my code. My stab at the problem is shown below. Can anyone suggest what my most efficient workable solution would be (i.e. I don't want to have to create instances of the classes as they will only store constant information and I would...
3
2742
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 particulars about my app 1) The front end is distributed as a .mde file. 2) Front end uses workgroup security 3) A separate logon form is used to actually launch the front end. 4) My app includes a backup front end form, that backups the front end...
34
3374
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 long double const_pi=0.0; lines to // rodata
3
2207
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 end from the server to the user's PC. I thought that this was a good idea since Access seems susceptible to corruption. I told the user to open the logon form and click the "Download" button, which would then replace the corrupt front end on his...
17
2068
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, keycode_PageDown. Calls to Glk functions are thus ugly and tedious. scriptref = glk.fileref_create_by_prompt( glk.fileusage_Transcript | glk.fileusage_TextMode, glk.filemode_WriteAppend, 0)
12
6126
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: class SuperClass { const CNST = 'Super class'; public static function getCnst () {
0
9266
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9127
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9020
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7878
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6602
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5926
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4435
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3128
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2467
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.