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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL and Delphi, need help 1

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
0
0
US
I have on one of our servers an MySQL database. I'm attempting to build a front end in Delphi for people to access and modify it. There are two tables in the db that I have joined in one sqlquery object in delphi, I then have one datasource connected to the query. The tables are information on projects, one table being general information about the project, the other is detailed information about plan approvals and the like. The detail table is set up so that each project has a number of different "items" such as plan approvals and inspections, and also dates, user who entered, and comments. A user needs to be able to add "items" from a list in the event that a new plan or inspection are required.

My problem(s) is that I need to view data from both tables, and update the data from the form. I'm not an SQL expert by any means, I took these classes in college but I'm getting rusty. I'm not entirely sure how to update, add or delete records in delphi using sql.

My plan is to have a search for a project number, then a list of matching records, select from that list, and then be able to add/update from there.

I just need to know how to put sql statments in code(buttons) and use that to update/edit the tables in the MySQL database.

I know it's an awful lengthy and broad question, but I would greatly appreciate any help at all. Just little hints could bring back some memory from school:) I've done this all before at one point or another...but this is what happens when you get old I guess;)

Thanks,
Jonah
 
Hi!
I don't have an answer for you... I got a new question, instead (sorry)! How did u connect with mysql server? Did u use the dbexpress sqlconnection component? If so... well, I'm trying to do that too, but I don't think I'm typing the right "Hostname" and "Database" Params. What does Delphi expects as these 2 params? I type the name of the server (my application runs on the server), and the name of the database (or what I presume to be the name of the database, since I don't know MySQL at all, I'm skilled in Oracle), but I cannot connect. Can u help me? Thank u

Emanuele, Italy
 
Hi Jonah,

I'm assuming you are using BDE here. You can let the user view the result from your TQuery in a DBGrid or a combination of TDBEdit boxes. You can then drop a TDBNavigator that will let you add, edit or delete records. However, this only works if your data comes from only one table. If your query combines the result from two tables or more, you have to use the TUpdateSQL if you want to add/edit/delete the result from the query.

Hope that helps, at least a bit. :)
 
Yes I am using BDE and yes I am joining 2 tables. I'm not sure how to use the updatesql though. Do you just put the code to update/add/delete in the component, and if so can't you just put that code into a normal sql query object? I'm a little confused.

And to emanueleqr, since I'm using BDE, and have never used dbexpress, I can't really help you out I don't think. I'm sorry. In my case I set up a datasource in windows that connected to my server and use that in delphi.
 
BDE has some restrictions while updating a Query with Joins.
What i would suggest it Have a join Query as a Look-up and use Two Queries to Updated two tables based on the Selection from the look-up query.

 
One quick question, slightyly unrelated: How can you take a variable that is an integer and make it a string. I remember doing, but forget how.

Thanks for all the help.
 
Jonah:

To convert an integer to a string, you can use the
"inttostr" function.

Emanuele
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top