Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with delphi 7 database manipulation 1

Status
Not open for further replies.

phillywilly

Programmer
Apr 8, 2009
3
GB
Okay, I have an Access database connected to an ADO dbgrid in delphi through ADO connections. there are a few problems I'm having with it.

Firstly, I have a lookup table for one of my columns set up in access, it's for a supplierID column, it gets the supplier ID number and the supplier name from a suppliers table for you to select from. This doesn't work in the delphi DBGrid, I have looked for ways to allow it to display but all I've found are complex blocks of code that don't work for me and that I don't have the skill to adapt.

Secondly, I have several buttons for manipulating the data such as delete, append, edit etc. However, these functions can all be done by just double clicking on the dbgrid and then editing it. is there any way I can block this from being done without using the buttons?

Thirdly, though this is less major, when in the program a user attempts to add a record without required fields entered, there is an automatic error given, is there any way I can change this error?

Thanks in advance for your help, if there's any other information you need, I'll be happy to give it to you.
 
I think most of the problems you've described can be solved by adding a data entry form, rather than allowing data entry in the grid. Set the grids OnKeyDown and OnMouseDown events to open the data entry form. Put a Save and a Cancel button on it. In the SaveBtnClick event, you'll have the opertunity to validate the entered fields befor calling Post. You can use (delphi menu) > DataBase > Form Wizard to generate the form.
... a lookup table ... doesn't work in...
In your entry form, put a TDBLookupComboBox on the form for the lookup field. In the Object Inspector, assign the DataSource and DataField accordingly. Set the ListSource to your lookup table name. Set the KeyField and ListField to the field name in your lookup table.

Secondly, I have several buttons for manipulating the data such as delete, append, edit etc. However, these functions can all be done by just double clicking on the dbgrid and then editing it. is there any way I can block this from being done without using the buttons?
Yes. In TDBGrid.Options, set dgAlwaysShowEditor to false and dgRowSelect to false.
Thirdly, though this is less major, when in the program a user attempts to add a record without required fields entered, there is an automatic error given, is there any way I can change this error
See above.

Roo
Delphi Rules!
 
I can't use the form wizard to set up the data entry form as the database format I'm using is apparently incompatible, I have no idea how to set it up so that it works manually.
 
Okay, forget that, I have set up all of it manually, now I am attempting to update the database with an ADOCommand component, I have managed to update all of the fields except the one associated with the lookup combo box.

The basic look of the code is:

ADOCommand1.CommandText:='UPDATE Stock SET SupplierID=''' + SupplierIDLookup + '''

But I don't know which property of the lookup field to set the database to update to.

Again, thank you very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top