Solved

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

Posted on 2004-10-14
6
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

688 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