Several methods of Delphi design database query

xiaoxiao2021-03-05  23

Several methods of Delphi Design Database Inquiry Delphi is too simple to design the database inquiries. In practical use, I possess the following points, share with you. (1) Filtering (1) Generally filtered the simplest and most common methods used when Delphi designed database queries. In the properties of the table (such as Table1), there is a Filter property, set the condition of this attribute value to query, the static setting method is to enter the condition after the value value, such as: XB = 'male' and NL <35, then Setting another attribute value of the table to true, table1.active is true, so that the eligible record can be seen in the DBGRID; the dynamic setting method is to set and change the condition according to the application during the operation of the program. At this time, use: with table1 do begin filter: = 'xb =' '' ' ' male ' ' '' ' ' and nl <35 '; Filtered: = true; (2) Query the record at a word To query the record of LI, enter: XM = 'plum *'; (3) Query field above the query field or graphics field is a normal field, if To query the fields such as MEMO, Picture, the example is required to check the resume not empty, and enter the Filter property value to: NOT (JL Is Null). (2) Dynamic setting using the SELECT statement (1) General conditions (such as DA.DB): with query1 do begin close; if prepared the unprepare; sql. Clear; SQL. Add ('SELECT * from Da where xm =: xm'); params [0]. Asstring: = 'Liu Qing'; prepare; Open; End; Static setting, as long as you enter the condition in the SQL attribute value of Query1, if the parameters are parameters (the condition value: variable name), set in the value set in params Enter the condition value, if you are words, you are case sensitive, set Query1's Active to true. (2) Change the displayed field name in the results of the query: If the original field name name of the query display is changed to Name: SELECT XM AS Name, XB, NL from DA This method can display different databases in DBGRID Out of the same field.

转载请注明原文地址:https://www.9cbs.com/read-35169.html

New Post(0)