Home > Back-end >  Delphi7 query added in all fields, add the SQL statements only search according to certain fields, f
Delphi7 query added in all fields, add the SQL statements only search according to certain fields, f

Time:09-26

Just learning soon Delphi, small white one,
Delphi7 query added in all fields, add the SQL statements only search according to certain fields, for other fields you don't need the old error, prompt can not find?
Add fields must show?
Then remove to a field, it can shows, but the search for other fields can't see again! How to solve?

CodePudding user response:

The query of the query, the query can be good for all of the fields addition,
You don't need to manually add,

Add in the query field, delete all, with respect to OK,

CodePudding user response:

reference 1st floor yangb0803 response:
query query, you can query all of the fields will be automatically add good,
You don't need to manually add,

Adding fields to query, delete all, with respect to OK,

I want to achieve a Boolean fields ongettext events, it is necessary to add a Boolean field, if only add the Boolean fields, only show when I was searching the Boolean fields, can't show the other fields, if removed, the Boolean field to show only the false or true, so struggle, I want to know is besides ongettext events, how to realize Boolean type field does not display the false or true, but the custom text display right or wrong?

Added a field or query, how to dynamically add other need to display the fields, because the show behind the search field has much less, before I check method is to add a few to make field, and then in the different search delete redundant field, use the method of destroy or free; But can be checked, not an error, but continue to click on the search button is an error, can't check in a row,

CodePudding user response:

The query result set fields to and SQL statements in the field to be consistent, such as the QL statement is:
 select number, name of the from table 

The field of the query should have number, name of the field

CodePudding user response:

 procedure TForm1. Button1Click (Sender: TObject); 

The begin
Query1. DatabaseName:=ExtractFilePath (opendialog1 FileName);
If memo1. Text="' then
The begin
Showmessage (' please select query file! ');
End
Else if listbox1. ItemIndex=1 then
The begin
Showmessage (' please select a category! ');
End
Else if (edit1. Text=' ') then
The begin
Showmessage (' please enter a value! ');
End
Else if listbox1. Items [listbox1 ItemIndex]='speed limit section then
The begin
Query1. Fields [5]. FieldName:='starting point km mark;
Query1. Fields [6]. FieldName:='end km mark;
Query1. Fields [7]. Destroy;//the trip caused an error, error message: query1: always perform this operation on an open dataset.
Query1. Close;
In query1.sql. The clear;
In query1.sql. Add (' select have cross road, SXX line, XXLX category code, CZM category, CZH station, BH beginning km mark, GLB end km mark ');
In query1.sql. Add (' from '+ ExtractFileName (opendialog1. FileName) + ");
In query1.sql. Add (' where XXLX="31" OR (BH=: BH1 and XXLX="83") OR (GLB=: BH1 and XXLX="83") ");//information query station or numerical and speed limit section type
Query1. Params [0]. AsInteger:=strtoint (edit1. Text);
Query1. Prepare;
Query1. Open;
Query1. Filtered:=false;
DBgrid1. Columns [0]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [0]. Alignment:=taCenter;//center content
DBgrid1. Columns [1]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [1]. Alignment:=taCenter;//center content
DBgrid1. Columns [2]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [2]. Alignment:=taCenter;//center content
DBgrid1. Columns [3]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [3]. Alignment:=taCenter;//center content
DBgrid1. Columns [4]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [4]. Alignment:=taCenter;//center content
End
end;

CodePudding user response:

 
Procedure TForm1. Button1Click (Sender: TObject);

The begin
Query1. DatabaseName:=ExtractFilePath (opendialog1 FileName);
If memo1. Text="' then
The begin
Showmessage (' please select query file! ');
End
Else if listbox1. ItemIndex=1 then
The begin
Showmessage (' please select a category! ');
End
Else if (edit1. Text=' ') then
The begin
Showmessage (' please enter a value! ');
End
Else if listbox1. Items [listbox1 ItemIndex]='speed limit section then
The begin
Query1. Fields [5]. FieldName:='starting point km mark;
Query1. Fields [6]. FieldName:='end km mark;
Query1. Fields [7]. Destroy;//the trip caused an error, error message: query1: always perform this operation on an open dataset.
Query1. Close;
In query1.sql. The clear;
In query1.sql. Add (' select have cross road, SXX line, XXLX category code, CZM category, CZH station, BH beginning km mark, GLB end km mark ');
In query1.sql. Add (' from '+ ExtractFileName (opendialog1. FileName) + ");
In query1.sql. Add (' where XXLX="31" OR (BH=: BH1 and XXLX="83") OR (GLB=: BH1 and XXLX="83") ");//information query station or numerical and speed limit section type
Query1. Params [0]. AsInteger:=strtoint (edit1. Text);
Query1. Prepare;
Query1. Open;
Query1. Filtered:=false;
DBgrid1. Columns [0]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [0]. Alignment:=taCenter;//center content
DBgrid1. Columns [1]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [1]. Alignment:=taCenter;//center content
DBgrid1. Columns [2]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [2]. Alignment:=taCenter;//center content
DBgrid1. Columns [3]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [3]. Alignment:=taCenter;//center content
DBgrid1. Columns [4]. Title. Alignment:=taCenter;//title center
Dbgrid1. Columns [4]. Alignment:=taCenter;//center content
End
end;

Currently using code, check all the required fields to add fields, and then to check the different data delete redundant fields, click ok for the first time, to find, but again at the click of a button an error, query1. Fields [7]. Destroy;//visit the error caused by error message: query1: always perform this operation on an open dataset. Delete redundant field, delete this statement is no problem, could you tell me how to solve?

CodePudding user response:

Query, there is no need to add field is loaded

CodePudding user response:

Reference
how to realize Boolean type field does not display the false or true, but the custom text display right or wrong?


The easiest way, in the SQL query processing,
Such as query languages:
 
nullnull
  • Related