Solved

How can I display the defaults defined on the database in the fields on insert?

Posted on 2004-10-14
6
135 Views
Last Modified: 2010-05-18
Hi all,

I'm using Delphi 7 with the excellent Devexpress component suites and MSSQL 2000 on XP.

I don't like coding the same things more than once and thus was wondering how would I go about to automatically display the default values (as defined in the database) in the relevant controls upon starting an insert.

I'm sure this must be possible and that I'm not the first to ask this.

Any comments are wlecome.

Regards,
Johan Swart
0
Comment
Question by:johan777
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 250 total points
ID: 12318673
Ehm, no. Not possible, afaik. This default data would be set by e.g. a trigger or other method, which means you have to read the metadata from your table to determine the correct values. You might try to add a new, empty record, read it's values and then delete this recordf again, using the values you've just read as default values. But it won't be able to process defaults set by triggers. (Because these could change every time.)
What you also could do is just insert a new record, read it's values. Then let the user edit this new record and if the user cancels the action, delete the record again. It's not a nice trick, though...
0
 

Author Comment

by:johan777
ID: 12327717
Hi Workshop Alex,

One can define the default on a column in the database. This default will be used if no value was supplied when a new record was inserted. also the default gets set by the DBMS and not via a trigger.

Alas, you are right, it seems that I would have to descend to such a vulgar way of programming as to write code to read the metadata if I want to prepopulate the defaults in the data-aware controls upon initiating an insert. :-(

I was just hoping there's a guru out there that knows of a way to do it swiftly, and cleanly.

 .. I wonder if there is a generic routine to read the metadata via ADO, so that I do not have to write different code for each database type that I want to query?

I'll bump the points up to 500 if I can get a solution on this last question of mine.

Regards,
Johan Swart
0
 

Author Comment

by:johan777
ID: 12565203
hi Alex,

Thanx for the response. I have decided to request this question closed as i did not receive an acceptable solution on this one.

I hope this is ok?

Regards,
Johan Swart

PS Sorry for taking so long, but the project I'm on was keeping me quite busy.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question