Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now