如何在delphi中读取sql数据库中的值?

diaorenhong 2001-07-05 08:09:37
我想问一下,如何在 delphi 中使用将sql_server中数据库表中的数据读出来,并且疑问本文档的形式存放在硬盘的某一目录中,
...全文
302 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
myxfang 2001-07-06
  • 打赏
  • 举报
回复
拉Adoconnection1和listbox1两个控件?
定义好adoconnection跟sql_server的连接?
adoconnection1.GetTableNames(listbox1.items);?
listbox1.Items.SaveToFile(路径);即可?
你是哪句看不懂?
wecan 2001-07-06
  • 打赏
  • 举报
回复
adoconnection1.GetTableNames(listbox1.items);
这个命令可以直接运行,意思:把所有的表放在listbox1上
listbox1.Items.SaveToFile(路径);
把listbox1上的数据保存在你指定的路径上比如:
listbox1.Items.SaveToFile('c:\table.txt');
diaorenhong 2001-07-06
  • 打赏
  • 举报
回复
adoconnection1.GetTableNames(listbox1.items);?
listbox1.Items.SaveToFile(路径);即可?
两句我看不懂,能不能蒋详细一点

wangxd1976 2001-07-05
  • 打赏
  • 举报
回复
有意思,用Query读出来,一行一行的写到一个文本文件中不就完啦

//把输出结果转换成文本文件
function ChangetoText(TextForm:Tform;Query1:TQuery;title:string;summary:string): Boolean;
var
I: integer;
FName,OutString: string;
OutFile: TextFile;
note: Tbookmark;
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.GetBookmark;
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.GotoBookmark(note);
Query1.FreeBookmark(note);
savedialog1.Destroy;
result := True;
end;
except
CloseFile(OutFile);
Query1.EnableControls;
Savedialog1.free;
Showmessage('过程错误,请退出后重新运行!');
Result := False;
end;
end;
tszw 2001-07-05
  • 打赏
  • 举报
回复
你到底想做什末????????????????????
liuzhiping 2001-07-05
  • 打赏
  • 举报
回复
讲清楚一点嘛,我没看懂
myxfang 2001-07-05
  • 打赏
  • 举报
回复
拉Adoconnection1和listbox1两个控件
定义好adoconnection跟sql_server的连接
adoconnection1.GetTableNames(listbox1.items);
listbox1.Items.SaveToFile(路径);即可
wolfAone 2001-07-05
  • 打赏
  • 举报
回复
什么意思呢?具体一点哦
snaker2001 2001-07-05
  • 打赏
  • 举报
回复
我也想知道,期待,期待!

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧