Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

24 Experts available now in Live!

Get 1:1 Help Now