RAD Studio XE8 uses controls to implement database additions and deletions

Source: Internet
Author: User

First, set up the database

    1. Decompression: Mysql-workbench-community-6.3.4-win32-noinstall, Mysql-5.6.25-win32
    2. Open Mysql-5.6.25-win32 to Bin, open Mysqld.exe, after execution automatically exit, open Mysql-workbench-community-6.3.4-win32-noinstall in MySQLWorkbench.exe, you can open Database, custom new connection can be, this is more convenient, after decompression directly use, no need to configure the environment.
    3. Unification of the character set of the data: utf-8_general_ci;
    4. Select UUID (): Query the table ID address, varchar32 bit storage;
    5. Storage of images: relative or absolute path//Direct storage (using BLOB type);
ii. settings in rad Studio XE8:Note: fdconnection, Tdatasource, fdquery are the matching
    1. New project, click Firedac in the Panel, select Tfdconnection;
    2. DriverName set to mysql,connected True (if an error occurs, copy the Libmysql.dll under the Lib directory to the C:/windows directory, note that you want to differentiate between 32-bit and 64-bit//or set path in the environment variable, Set the path to MySQL);
  1. Fill in the params with database name, Port (3306), user name (typically root), password, server IP address
  2. Note: loginprompt to False,chracterset to UTF8, click Connection set to TRUE;
  3. Find TFDQuery1, set connection to FDconnection1, write SQL statements in SQL, generally query, click Ok;active set to True;
  4. In the palette data access find Tdatasource, put in form, double click on the dataset to get FDQuery1
  5. You can add multiple components, then open view->livebindings Designer, connect the properties and components in the Panel, the component is editable edit, the arrow is bidirectional when it is modifiable, the component is read-only, and the arrow is one-way, which is read-only;
  6. Set true in active in FDQuery1, and run to display database data when you drag the FDGUIxWaitCursor1 component into the form.

Third, the realization of multi-data query and operation

    1. Add multiple buttons, double-click Method, write This->datasource1->dataset->, according to Next, Prior, first, last, can display the data of different positions;
    2. In the SQL column of FDQuery1, different data are displayed according to the different SQL statements;
Four, conditionally query (with component control, no code involved)
    1. Find TFDQuery1, write SQL statements in SQL, such as where Age=:age (: The following is the name you can take, age, ABC, and so on);
    2. Select the ellipsis in Prames, double-click the content, and select DataType as ftstring (depending on the type of attribute in the database), the box below will meet the criteria and fill in the Value box.
    3. Set Active to True when the bullet box is closed.
Five, delete (with code control, the remaining additions and deletions are similar)
    1. Find TFDQuery1, write SQL statements in SQL, such as where Age=:age (: The following is the name you can take, age, ABC, and so on);
    2. Select the ellipsis in Prames, double-click the content, and select DataType as ftstring (depending on the type of attribute in the database), the box below will meet the criteria and fill in the Value box.
 //Note Here you can pre-set the SQL statement, variable ID, NAME, after executing the current statement to be followed by a SELECT statement, or errorvoid __fastcall Tform1::button1click (tobject *sender){this->fdquery1->active = false;this->fdquery1->parambyname ("ID")->asstring = this->editquery->text;this->fdquery1->parambyname ("NAME")->asstring = this->edit6->text;this->fdquery1->active = true; this->fdquery1->active = false;this->fdquery1->sql->clear ();this->fdquery1->sql->add ("select * from Hello.") User ");this->fdquery1->active = true;  }

No need to set the variable ad in advance, if using this->fdquery1->execsql (); no new SQL statement required

void __fastcall Tform1::button2click (tobject *sender){//select * from Hello. User where Id=:id and username=:name;this->fdquery1->active = false;this->fdquery1->sql->clear ();This->fdquery1->sql->add ("Delete from Hello.") User where Address=:ad ");this->fdquery1->parambyname ("AD")->asstring = this->edit6->text;//Do not need to be set in Prames, asstring is similar to datatype selected as ftstring specified type, if the ID should be changed to Asinteger.This->fdquery1->execsql (); }vi. processing pictures (uploading and displaying)1, in the original data source operation, put in the ImageControl1 component, point to the Picture property, the first by the modified or New button, the necessary code is: (Ensure that the code before clicking on the image box to execute)

This->datasource1->dataset->edit ();

2, make the picture frame in the editing state, and then insert the picture, press the Save button, the code is:this->datasource1->dataset->fieldbyname ("picture")->assign(THIS->IMAGECONTROL1->BITMAP);
this->datasource1->dataset->post (); 



 

RAD Studio XE8 uses controls to implement database additions and deletions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.