Solved

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

Posted on 2004-10-14
6
137 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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