I have been studying Delphi for a week. Delphi is a derivative of Pascal, but it is easy to learn Pascal. Of course, I have learned VB (visual basic). Of course, I am relatively familiar with this language, but I don’t learn it after a long time. I also forgot a lot, but I got started with Delphi much faster, especially the book I am learning now is about Delphi database design. During the learning process, many of the bundled database controls such as ADO when I was learning VB. , so it is easy to learn, but designing to applications and grammar still needs further learning.
Now I want to talk about learning SQL commands and ADOquery components, SQL Select statements and dynamic execution of SQL statement commands. Here SQL (Structrue Query Language) is a structured query language. It has the basis for me and can be used. Faster. Of course, it is noted that this is connected to the corresponding database through ConnectiongString in the ADOquery component property. Three components are added to the form: ADOquery, DataSource, and DBGrid. When you drag a DataSource component, its name is DataSource1 and put it The property DataSet of the property DataSet is set to ADOquery1; the property DataSource of DBGrid1 is set to DataSource1. Speaking of this, I think of the relationship between the program components and the database, that is, why do I need to drag these components and what kind of analytical relationship is there between them. Woolen cloth? As shown in the figure below
Table/ADOTable DataSource DBGrid.....
Connect components ------------------------------------------------------------------------------------------------------------------------------
Relationship between components
Let me explain: The most important key component in database programming is the Table component (Ttable or TADOTable component) connected to the database. This database connection component is responsible for connecting to the tables in the database file. If we want to add, delete, edit, and retrieve data, we must also use the relevant methods, properties, and events of this component. Here we just need to connect, and there is no need to care about anything else. When the connection component connects the table in the database file, the contents of this table cannot be delivered directly to the database-aware component (such as DBGrid) and displayed. It must be handed over to the DataSource component to parse the contents of the table, and then the parsed table will be parsed. The contents are delivered to the database-aware component (such as DBGrid) to display, which is shown in the figure above. Of course, the perception component also has DBNavigator. These can be displayed by parsing the data, but the specific ones also need to write program statements to complete.
Speaking of this, I still have to continue to enter SQL operations, which is the most important thing, I personally think. SQL Select is very important. Everyone must refer to some database books and read more, and it is best to debug in the computer environment. For example: it is also very important to change the field name. Generally, when we are working on projects, the fields of the table in the database are in English, but when displaying, in order to make people familiar with it, we have to display it in Chinese. You must be familiar with these basic operations such as order by sorting, where conditional filtering, etc.
Next is to dynamically execute SQL commands, which is also very important in reality. For example, we generally use the ComboBox component to select the required fields, such as the name in a certain table. After selecting, the perception component will be displayed. Isn’t this very convenient for the name you specified? Of course, it is also necessary in reality. This is how the dynamics came about! Here is the code in the OnChange event program of the ComboBox component:
PRocedure TForm1.ComboBox1Change(Sender: TObject);
//Declare string variables for loading sql command
var
MySQL:string;
Begin
//Create basic SQL command content
mysql:='select * from transcript order by ';
//Cancel the database connection
adoquery1.Close; or adoquery1.Active:=false;
//Clear the original SQL command
adoquery1.SQL.Clear;
//Connect new SQL commands
adoquery1.sql.Add(mysql+combobox1.Text);
//Re-establish the database connection
adoquery1.Open;
//Show the content of the currently used SQL command in the title bar
caption:=adoquery1.SQL.Text;
//Specify a new sql command
//adoquery1.SQL.Add(combobox1.Text);
//Connect the database with new SQL command
adoquery1.Active:=true;
end;
end.
The above are some simple applications of SQL I learned in Delphi for your reference!