拉Adoconnection1和listbox1两个控件
定义好adoconnection跟sql_server的连接
adoconnection1.GetTableNames(listbox1.items);
listbox1.Items.SaveToFile(路径);即可
定义好adoconnection跟sql_server的连接
adoconnection1.GetTableNames(listbox1.items);
listbox1.Items.SaveToFile(路径);即可
function ChangetoText(TextForm:Tform;Query1:TQuery;title:string;summary:string): Boolean;
var
I: integer;
FName,OutString: string;
OutFile: TextFile;
note: Tbook;
savedialog1: Tsavedialog;
begin
//创建对话框的容器
try
savedialog1 := Tsavedialog.Create(TextForm);
//Assign a filename to the variable
savedialog1.Filter := 'Text files (*.txt)|*.TXT';
if savedialog1.Execute then
FName := savedialog1.FileName+'.txt';
if FName <> '' then
begin
note := Query1.GetBook;
Query1.DisableControls; //Identify the filename and type as OutFile
AssignFile(OutFile,fname); //create and open a new file identify as OutFile
Rewrite(OutFile); //插入标题
OutString := title+#13;
Writeln(OutFile,OutString);
OutString := ''; //Get text from the Query1
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+Query1.Fields[i].displaylabel;
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring;
end;
end;
Writeln(OutFile,OutString);
OutString := ''; While not Query1.EOF do
begin
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+'"'+Query1.Fields[i].AsString+'"';
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring ;
end;
end;
//Write out the text in OutString to file
Writeln(OutFile,OutString);
Query1.Next;
OutString := '';
end; //插入总结
Writeln(OutFile,summary);
//Update and close the file
CloseFile(OutFile);
Query1.EnableControls;
Query1.GotoBook(note);
Query1.FreeBook(note);
savedialog1.Destroy;
result := True;
end;
except
CloseFile(OutFile);
Query1.EnableControls;
Savedialog1.free;
Showmessage('过程错误,请退出后重新运行!');
Result := False;
end;
end;
定义好adoconnection跟sql_server的连接?
adoconnection1.GetTableNames(listbox1.items);?
listbox1.Items.SaveToFile(路径);即可?
你是哪句看不懂?
listbox1.Items.SaveToFile(路径);即可?
两句我看不懂,能不能蒋详细一点
这个命令可以直接运行,意思:把所有的表放在listbox1上
listbox1.Items.SaveToFile(路径);
把listbox1上的数据保存在你指定的路径上比如:
listbox1.Items.SaveToFile('c:\table.txt');