0
To read the file . DBF works as follows:
I use a Tadoconnection, being the Connectionstring for:
Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=C:\_workspace\projects\DBFEditor\temp
To read the DBF file use a Tadoquery setting the SQL property for the query:
Select * from <arquivodbf>
So I have these columns in my dbf file.
INDICE NOME COR ESTILO ESCALA
100 SAOJOAO 18 0,00
I need to change the name of the column INDEX FOR ID, for this I am doing as follows:
while not ADOQuery1.Eof do
begin
Adoquery1.Edit;
ADOQuery1.FieldByName('NOME').TEXT:= 'ID';
Adoquery1.Post;
ADOQuery1.Next;
end;
however I get the following result, when opening my excel:
INDICE NOME COR ESTILO ESCALA
ID SAOJOAO 18 0,00
how I expect the result:
ID NOME COR ESTILO ESCALA
100 SAOJOAO 18 0,00
You do not change the name of the column, only change data on them. It should have some form, but in Delphi I do not know how to do, only externally.
– Maniero
But technically I’m setting a value, the INDEX field, it’s still a field
– Guilherme Lima
What I understand is that you want to change his name, this is a complex operation that Ado should not be able to do, at least not in a traditional way. Changing data is one thing, changing the column name is another. And this code is very confusing, to tell you the truth that it’s posted there doesn’t even really happen.
– Maniero
Exactly what I need, I’ll switch to a simpler way, but it’s working yes.
– Guilherme Lima
You indicate some way you might be doing this?
– Guilherme Lima
Just so I understand better, you have one. dbf and to connect to such database using the TADO component, traversing the records with Adoquery and saving the information in Excel?... if I’m wrong correct me.
– Jefferson Rudolf
Exactly, the issue @bigown said is that it is not possible to change the "header" that would be the first line of the file using DAO
– Guilherme Lima
In this case, the best way is to assemble a command
alter
, and run directly with Delphi. Just use theExecuteDirect()
ofSQLConnection
.– Victor Tadashi
Just to complement this command you use
ADOQuery1.FieldByName('NOME').TEXT:= 'ID';
is explicit that you are changing the contents of Field 'NAME' when you use . Text which is a property of the object.– Victor Tadashi
@Jeffersonrudolf, from what I understand, wants to change Field’s name, not the content. Unless I’m mistaken.
– Victor Tadashi
Exactly, I want to change FIELD’s name
– Guilherme Lima
In order to change the fields, you have to go through them, do the following... before you go through the information you have to change the Fields and then feed the data. Try doing a for in Adoquery.FieldsDefs.Cout-1 and taking the first Field, doing so... Adoquery1.Fieldsdefs[0]. Name := 'ID'
– Jefferson Rudolf
@Victorzanella, he has to go through the query’s Fields in order to change
– Jefferson Rudolf
I think it would be easier for you to set up an external command, as @bigown thought, and this command you run by your Sqlconnection. Ex
MySQLConnection.ExecuteDirect('ALTER TABLE table_name ALTER COLUMN column_name datatype')
– Victor Tadashi
@Victorzanella you could formulate a response with what commented? would help a lot
– Guilherme Lima
I didn’t formulate an answer, because I’m not sure. What happens is that at no point did you say you were using any database. I deduced this by the file extension. Dai I don’t know if you really use an Sqlconnection. If you confirm this for min, Edit your question by putting more code, I could formulate an answer.
– Victor Tadashi
I have improved the question, in case it is not yet clear can send here or call me by chat
– Guilherme Lima
@Guilhermelima, it would be interesting to pass the contents of Adoquery to a temporary table of Delphi, a very good component to manipulate this data would be the Tclientdataset, you create the Fields that you want and go through your Adoquery feeding the Clientdataset, after you have updated Clientdataset, just go through it and mount the data to be viewed in Excel.
– Jefferson Rudolf