procedure TForm1.Button1Click(Sender: TObject); var Myfile:textfile; i:integer; s:string; begin assignfile(Myfile,'out.txt'); reset(Myfile); query1.First; while not query1.Eof do begin for i:=0 to DBGrid1.Columns.Count-1 do begin s:=DBGrid1.Columns[i].Field.Text; Append(Myfile); writeln(Myfile,s); end; query1.Next; end; end; 在程序的文件夹里建立个空的文本文档。在form上放一个query,datesourse,dbgrid,buttonquery的SQL里面写入你的表,运行一下! 我试了! 没问题!
呵呵,楼主问的是用SQL语句实现
看看,去查一下SQL Server的联机帮助。
查一下SQL Server的联机帮助。
将SQLServer导入到文本文件 ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False' ADOConnection.Connected := True; ADOConnection.Execute('SELECT * into aaa.txt FROM Tab1 IN [ODBC] [ODBC;Driver=SQL Server;UID=sa;PWD=;Server=127.0.0.1;DataBase=test;]');
你用的什么数据库,SQLSERVER可以用BCP。
不好意思,偶记错了 ‘out’是用bcp导的 Data can be bulk copied to or from a view. This includes copying data from multiple joined tables, adding a WHERE clause, or performing special formatting such as changing data formats using the CONVERT function. For example, to bulk copy data from the view titleview in the pubs database to the Titleview.txt data file, execute at the command prompt:bcp pubs..titleview out titleview.txt -c -Sservername -Usa -Ppassword To bulk copy data into a view using bcp or the BULK INSERT statement, the rules for inserting data into a view apply. ------------- sql语句怎么实现偶也不知道
不同的DBMS写法不同的
var
Myfile:textfile;
i:integer;
s:string;
begin
assignfile(Myfile,'out.txt');
reset(Myfile);
query1.First;
while not query1.Eof do
begin
for i:=0 to DBGrid1.Columns.Count-1 do
begin
s:=DBGrid1.Columns[i].Field.Text;
Append(Myfile);
writeln(Myfile,s);
end;
query1.Next;
end;
end;
在程序的文件夹里建立个空的文本文档。在form上放一个query,datesourse,dbgrid,buttonquery的SQL里面写入你的表,运行一下! 我试了! 没问题!
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp;Extended Properties="text;HDR=YES;";Persist Security Info=False'
ADOConnection.Connected := True;
ADOConnection.Execute('SELECT * into aaa.txt FROM Tab1 IN [ODBC]
[ODBC;Driver=SQL Server;UID=sa;PWD=;Server=127.0.0.1;DataBase=test;]');
Data can be bulk copied to or from a view. This includes copying data from multiple joined tables, adding a WHERE clause, or performing special formatting such as changing data formats using the CONVERT function. For example, to bulk copy data from the view titleview in the pubs database to the Titleview.txt data file, execute at the command prompt:bcp pubs..titleview out titleview.txt -c -Sservername -Usa -Ppassword To bulk copy data into a view using bcp or the BULK INSERT statement, the rules for inserting data into a view apply.
-------------
sql语句怎么实现偶也不知道