关于使用ADO将数据库中的一张表保存为一个文件的问题(80分)

  • 主题发起人 主题发起人 daisyrose
  • 开始时间 开始时间
D

daisyrose

Unregistered / Unconfirmed
GUEST, unregistred user!
源代码如下,运行后不能在C盘根目录下找到文件XIATIAN。RST,DJ是我要保存的那张表,XIATIAN。RST是我要保存的文件名
RS:TFIELD;
st:='c:/XIATIAN.rst';
sqlorder:='select * from lL.DJ';
adodataset1.Recordset:=form1.ADOCONNECTION1.execute(sqlorder);
rs:=form1.ADODataSet1;
rs.SaveToFile(ST);
 
RS:TFIELD;
rs:=form1.ADODataSet1;

这个怎么解释?rs不是field么?怎么把dataset给他了??你的代码好难看懂哦
 
看不懂,这段代码你能通过吗?这样吧.
var
st,sqlOrder: String;
begin
st:='c:/XIATIAN.rst';
sqlorder:='select * from customer';
adodataset1.Recordset:=form1.ADOCONNECTION1.execute(sqlorder);
AdoDataSet1.SaveToFile(st,pfXML);
end;
 
我一般是这个样子的:
with ADOQuery1 do
begin
Close;
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=raiboi';
SQL.Text := 'SELECT * FROM AUTHORS';
Open;
SaveToFile('no1.xml', pfXML);
end;
不知行不行?
 
taozhiyu我的RS也许是不该设置,可是改成直接用ADODATESET1。SAVETOFILE仍然不可以存上文件
还有GANQUAN的代码也不能生成文件也,RAIBOI你说要用到QUERY,可是我的程序中没有这个预算,
还有其它方式吗
 
只要是 TCustomADODataSet 都有这个方法
ADOTable 也是.
 
可是我也没有用ADOTABLE啊,我只用了ADOCONNECTION,ADODATASET和ADODATASOURCE
 
没有这样用过!
学学!

to raiboi: 你用 XML ?
 
不知道你要保存成什么文件,如果是xml的话上面的代码应该行了。
如果是mdb,dbf,txt这些文件的话可以用两个recordset加上一个batchmove,
分别配置两个recordset的数据来源(txt文件用microsoft text driver引擎),然后用
batchmove来导数据
 
to jrq :
没什么问题吧?
 
程序的其它部分都是用的上述几个控件做的,因此我不想为了SAVE而再用TABLE等
我想保存成便于导入的文件,到了另一台具有相同数据库的机器上可以顺利地将文件导入到
其中成为一个独立的表,采用RST格式也只是一说
 
TCustomADODataSet.SaveToFile
-----------------------------
TCustomADODataSet
================================
Saves a recordset to a file.
procedure SaveToFile(const FileName: String = ''; Format: TPersistFormat = pfADTG);
Description
Call SaveToFile to save the current recordset to a file. If the destination file already exists, it is overwritten.
FileName is a string containing the name of the destination file. This file remains open from the first call to SaveToFile until the dataset is closed. This file can be read by other applications while it is open, but they cannot write to the file.
Format specifies the file format for the saved recordset. By default, Format is pfADTG (Advanced Data Tablegram format).
Note: Microsoft recommends using a client-side cursor (the dataset is opened with a CursorLocation property value of clUseClient). This way, if the provider used does not support saving the recordset the client cursor will provide the necessary functionality

TCustomADODataSet.LoadFromFile
TCustomADODataSet
===================================
Loads a recordset from a file.
procedure LoadFromFile(const FileName: WideString);
Description
Call LoadFromFile to load the recordset for the calling ADO dataset component from a file. If the loading operation fails, the current recordset is neutralized (set to nil), the dataset component remains inactive, and an EOleException exception is raised. If the attempt to load data from a file is successful, the ADO dataset component is automatically activated and the data made available.
FileName is a string containing the name of the file.
LoadFromFile closes the dataset component before loading the recordset from the file specified in FileName.

 
不能保存?我怎么可以?
这样保存下来虽然是rst后缀,但还是XML格式。不如就叫Xiantian.XML
到其他地方,用ADODataSet来loadfromfile就行了。
 
真的不能存也,不是报错,就是在文件生成路径下根本找不到这个文件
 
如果结构不是很复杂的话,可以试试使用自定义结构体存储,这样很方便也比较高效
 
最后还是用的结构存档
 
后退
顶部