当前位置:主页>销售管理软件> 列表

ADODataSet怎样将一条或多条记录存储到流中 找免费小型财务软件

进销存软件版1楼: GetCurrentRecord不行,有没有简单的方法呀

2楼: ADOQuery1.SaveToFile 如excel进销存模板

3楼: 我要求用ADODataSet

4楼: 其实TADODataSet、TADOQuery均从TCustomADODataSet继承的:

ADODataSet1.SaveToFile();
以下载自delphi在线帮助:
TCustomADODataSet.SaveToFile
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.

5楼: 這個我可以解決一條記錄問題,但要解決多條記錄我還要修改自己方法才行。
技術交流QQ:136293586

6楼: 有那就是你可以借助datasetprovider和clientdataset來實現。可以建立流變量來實現保存。代碼如:function DySavetoFile(const Sdata:Tclientdataset;Fname:string):boolean;
Var
Pstream:TFilestream;
kname:string;{kname保存文件相對路徑其中Fname具備兩用性:
作為離線數據包得開關值和保存數據包得文件名}
begin
Try
kname:=Get_path;
Pstream:=Tfilestream.Create(kname+Fname+''.dat'',Fmcreate);
Sdata.SaveToStream(Pstream,Dfbinary);
{寫入對應數據包已加載離線數據開關值}
WriteINI(kname+''client.ini'',''DataCache'',Fname,''1'');
finally
Pstream.Free;
end;
end;
這個你可以參照下。

进销存软件版7楼: 復制一條或多條記錄:
Procedure TForm1.AppendCurrentReCordset(SetRecord:Integer;SourceData,TargetData:Tdataset);
Var
aField : Variant ;
x, y: Integer ;
Begin
aField := VarArrayCreate([0,SetRecord-1, 0,SourceData.Fieldcount-1],VarVariant);
For X:=0 To SetRecord-1 Do Begin
For Y := 0 to (SourceData.Fieldcount-1) Do
aField[X,Y] := SourceData.fields[Y].Value ;
SourceData.Next;
End;

For X:=0 To SetRecord-1 Do Begin
TargetData.Append;
For Y := 0 to (TargetData.Fieldcount-1) Do
TargetData.fields[Y].Value := aField[X,Y] ;
End;
End;

調用方法是:
  AppendCurrentReCordset(5,ADOTable1,ADOTable2);

注意事項是:
 SourceData,TargetData這兩個源數據集與目標數據集的類型結構一樣

8楼: to bbscom
还行,不过还是不理想,不过你肯定有分了

9楼: to chnplzh
你的方法是不是让我这样操作呢?:
ADODataSet.SaveToFile(''123.txt'',Fmcreate);
MyStream.LoadFromFile(''123.txt'');

结果都是乱码

10楼: 帮顶!


http://www.source520.com

站长开发推广同盟 站长朋友的终极驿站
同时拥有海量源码电子经典书籍下载

http://www.source520.com/search/search.asp

"编程.站长"论坛搜索引擎-----为中国站长注入动力!

11楼: 如下操作:
首先,你可以把记录保存为ClientDataSet可以接受的Variant,然后你就可以对CDS里的数据进行操作了,非常方便!!
uses Provider;

function DataSetToVar(ADataSet: TDataSet;
Recs: Integer): olevariant;
var
DPW: TDataPacketWriter;
V: OleVariant;
BK: TBookMarkStr;
begin
if ADataSet <> nil then
try
DPW := TDataPacketWriter.Create;
DPW.PacketOptions := [grMetaData];
ADataSet.DisableControls;
BK := ADataSet.Bookmark;
ADataSet.First;
DPW.GetDataPacket(ADataSet, Recs, V);
finally
DPW.Free;
ADataSet.Bookmark := BK;
ADataSet.EnableControls;
end;
Result := V;
end;
recs代表要转换的记录,-1为全部.
用法:
ClientDataSet1.Data := DataSetToVar(AdoQuery1, -1);

如果你想进行流操作,可以用ClientDataSet1.SaveToStream和ClientDataSet1.LoadFromStream
也可用进行如下函数:
function VarToStream(Const Data: OleVariant): TStream;
var
P: Pointer;
Stream: TStream;
begin
Stream := TMemoryStream.Create;
P := VarArrayLock(Data);
try
Stream.write(P^, VarArrayHighBound(Data, 1)+1);
finally
VarArrayUnlock(Data);
end;
Result := Stream;
end;
function StreamToVar(Stream: TStream): OleVariant;
var
P: Pointer;
begin
Result := VarArrayCreate([0, Stream.size -1],Varbyte);
P := VarArrayLock(Result);
Try
Stream.Position := 0;
Stream.Read(P^, Stream.size);
Finally
VarArrayUnlock(Result);
end;
end;

12楼: 多人接受答案了。 如免费小型财务软件