function AdoToJs(ado: TADOQuery): string;
var
I, J: Integer;
json: string;
begin
json := '{columns:[';
for I := to ado.FieldCount - do
begin
json := json + '{name:"' + ado.Fields[I].FieldName + '",type:"' + DbTypeToStr(ado.Fields[I].DataType) + '"}';
if I < ado.FieldCount - then
json := json + ',';
end;
json := json + '],rows:[';
for I := to ado.RecordCount - do
begin
json := json + '{';
for J := to ado.FieldCount - do
begin
json := json + ado.Fields[J].FieldName + ':"' + ado.FieldByName(ado.Fields[J].FieldName).AsString + '"';
if J < ado.FieldCount - then
json := json + ',';
end;
json := json + '}';
if I < ado.RecordCount - then
json := json + ',';
end;
json := json + ']}';
Result := json;
end; function AdoToXml(ado: TADOQuery): string;
begin
Result := RecordsetToXMLString(ado.Recordset);
end; function XmlToAdo(xml: string): TADOQuery;
var
ado: TADOQuery;
begin
ado := TADOQuery.Create(nil);
ado.Recordset := RecordsetFromXMLString(xml);
Result := ado;
end; function RecordsetToXMLString(const Recordset: ADOInt._Recordset): string;
var
RS: Variant;
Stream: TStringStream;
begin
Result := '';
if Recordset = nil then
Exit;
Stream := TStringStream.Create('', TEncoding.UTF8);
try
RS := CreateOleObject('ADODB.Recordset');
RS := Recordset;
RS.Save(TStreamAdapter.Create(Stream) as IUnknown, adPersistXML);
Stream.Position := ;
Result := Stream.DataString;
finally
Stream.Free;
end;
end; function RecordsetFromXMLString(const xml: string): ADOInt._Recordset;
var
RS: Variant;
Stream: TStringStream;
begin
Result := nil;
if xml = '' then
Exit;
try
Stream := TStringStream.Create(xml, TEncoding.UTF8);
Stream.Position := ;
RS := CreateOleObject('ADODB.Recordset');
RS.Open(TStreamAdapter.Create(Stream) as IUnknown);
Result := IUnknown(RS) as ADOInt._Recordset;
finally
Stream.Free;
end;
end; function DbTypeToStr(dbtype: TFieldType): string;
begin
Result := GetEnumName(TypeInfo(TFieldType), Ord(dbtype))
end; function StrToDbType(const dbtype: string): TFieldType;
begin
Result := TFieldType(GetEnumValue(TypeInfo(TFieldType), dbtype));
end;

http://www.cnblogs.com/toosuo/archive/2012/02/18/2357315.html

最新文章

  1. HikariCP
  2. Sprint(第八天11.21)
  3. AndroidManiFast 字段意义
  4. Hadoop HDFS 架构设计
  5. 【spring 配置文件】spring配置文件的解析
  6. Auto push git tag
  7. 减少C++代码编译时间的方法
  8. 把Nginx加为系统服务(service nginx start/stop/restart)
  9. ADO.NET(很精彩全面)
  10. Spring整合CXF步骤,Spring实现webService,spring整合WebService
  11. Ubuntu系统、开发环境配置
  12. JavaScript高级程序设计13.pdf
  13. 成都Uber优步司机快速注册攻略(外地车牌也可加入,不用现场培训)
  14. 无法打开物理文件mdf,操作系统错误 5:&amp;quot;5(拒绝訪问。)&amp;quot;
  15. OpenStack命令 创建网络和路由管理
  16. android调用系统相机进行视频录制并保存到指定目录
  17. C++11新特性之tie、tuple的应用
  18. Android6.0运行时权限(基于RxPermission开源库)
  19. appium工作原理
  20. airTest 使用体验

热门文章

  1. Cisco IOS images
  2. 数据局部性(data locality)
  3. Warning: file_put_contents(常用单词1.txt): failed to open stream: Invalid argument in
  4. DesignPattern_Java:SingletonPattern
  5. lipo: can&#39;t open input file
  6. Ubuntu server使用命令行上板VPNclient
  7. Arcgis api for javascript学习笔记(4.5版本) - 获取FeatureLayer中的graphics集合
  8. this解析
  9. 取消Jquery mobile自动省略的文本
  10. Why I Choose Delphi Summary