Home > Back-end >  Delphi database operations
Delphi database operations

Time:09-26

Delphi adoconnection database, the basic query, insert, update, delete can be realized, met two questions now, please god help,
1, how the position of the insert is set in the specified location,
2, update the database problem: only the first column of the last line of the database table, don't know what is this element; Other is empty, how do I read this column, and then complete, according to the requirements of table to update again,

CodePudding user response:

Simple method is to use the dbgrid directly inside the form,

CodePudding user response:

The first question: data table data sequence is by keyword, if you want to insert in the location specified records, need to have a certain number of fields,
The second question: can through the DataSet) Fields [I] access, I field is the serial number subscript,

CodePudding user response:

The first question, you know, the value of the specified field, such as: fields: ID, value: 1234567890
So, can by the following code

Var s: a string;
The begin
S:='1234567890'.///S:=Trim (Edit1. Text);
With Query1 do
The begin
First;
Whilw Not Eof do
The begin
If FilednyName (' ID '.) asString=S
Then break;
Next;
End
First;//no returned to first line
end;
end;


The second question,

Should be to read and write values character corresponds to a DBEdit or DBCombobox, so you can at any time, see the value of the word, and can be set into the corresponding value,

CodePudding user response:

Please change the break in the code above to the exit

CodePudding user response:

Thank you, the second problem is that there are multiple records in the database, each record for a line is composed of multiple elements, the purpose is to search a database of the latest data, don't know the specific it in the concrete which line, line search condition is a only one element of the line, take out the data, how to implement?

CodePudding user response:

You this is SQL problem, anyway, I do every table, there must be a field called id, increase type automatically, it can't be wrong to listen to the elder brother, each table, tube he useful useless,

Select * from table where id=? Or
Select * from table order by id desc is reverse order, you can check the latest one record in the front is a add a top 1

CodePudding user response:

How to upload the current time in the database? Time column in the database is timestamp type

CodePudding user response:

refer to 7th floor kennylinlin response:
how to upload the current time in the database? Time column in the database is timestamp type


You want to update the current time, with a datetime type fields to store,
The update TBL
The set dt=getdate () the where...

Timestamp type fields, it is the system automatically update maintenance. Can't seem to update language sentence
  • Related