我已经用代码实现不同数据源如SQL与ORACLE之间的导入导出,现在问题出在将数据从数据库导出到文本文件中,报错: 文本文档定义不完整,该文件无法打开!附定义文件格式Delphi代码: begin for i := 1 to pConn.ConnectionProperties.Count do begin sPropertyName := pConn.connectionproperties.item(i).Name; if sPropertyName = 'Mode' then pConn.ConnectionProperties.Item(i).Value := iMode; if sPropertyName = 'Row Delimiter' then pConn.ConnectionProperties.Item(i).Value := #13+#10; if sPropertyName = 'File Format' then pConn.ConnectionProperties.Item(i).Value := 1; if sPropertyName = 'Column Delimiter' then pConn.ConnectionProperties.Item(i).Value := #9; if sPropertyName = 'File Type' then pConn.ConnectionProperties.Item(i).Value := 1; if sPropertyName = 'Skip Rows' then pConn.ConnectionProperties.Item(i).Value := 0; if sPropertyName = 'First Row Column Name' then pConn.ConnectionProperties.Item(i).Value := False; if sPropertyName = 'Column Names' then pConn.ConnectionProperties.Item(i).Value := 'OrgCode,SaleNo,'+ 'XsDate,TranType,PageNo,LnNo,ClkID,ClkCode,PackType,PackCode,PluID,PluCode' if sPropertyName = 'Text Qualifier' then pConn.ConnectionProperties.item(i).Value := ''''; if sPropertyName = 'Number Of Column' then pConn.ConnectionProperties.Item(i).Value := iNumberOfColumn; if sPropertyName = 'Text Qualifier Col Mask: 0=no,1=yes,e.g. 0101' then pConn.ConnectionProperties.Item(i).Value := '1111'; if sPropertyName = 'Max characters per delimited column' then pConn.ConnectionProperties.Item(i).Value := 8000; if sPropertyName = 'Blob Col Mask: 0=no,1=yes,e.g. 0101' then pConn.ConnectionProperties.Item(i).Value := '0000'; end; 未知原因,请赐教,如有VB,VC,JAVA,Ruby语言的转化源代码也不胜感激。或者给出connectionproperties的所有 属性,我去Miscosoft的帮助中没有找到,亦或有知道的给我发个链接或者地址都行,多谢~
用DELPHI的ADOQUERY就行了。很简单的。 procedure TForm1.Button1Click(Sender: TObject); begin self.ADOQuery1.SQL.Text := 'select * from test'; self.ADOQuery1.Open; self.ADOQuery1.SaveToFile('C:\TEST.TXT'); end;
不够清楚?用代码来实现用DTS形式将数据库中表的数据转化成文本形式保存在.txt文档当中。
我已经用代码实现不同数据源如SQL与ORACLE之间的导入导出,现在问题出在将数据从数据库导出到文本文件中,报错:
文本文档定义不完整,该文件无法打开!附定义文件格式Delphi代码:
begin
for i := 1 to pConn.ConnectionProperties.Count do
begin
sPropertyName := pConn.connectionproperties.item(i).Name;
if sPropertyName = 'Mode' then
pConn.ConnectionProperties.Item(i).Value := iMode;
if sPropertyName = 'Row Delimiter' then
pConn.ConnectionProperties.Item(i).Value := #13+#10;
if sPropertyName = 'File Format' then
pConn.ConnectionProperties.Item(i).Value := 1;
if sPropertyName = 'Column Delimiter' then
pConn.ConnectionProperties.Item(i).Value := #9;
if sPropertyName = 'File Type' then
pConn.ConnectionProperties.Item(i).Value := 1;
if sPropertyName = 'Skip Rows' then
pConn.ConnectionProperties.Item(i).Value := 0;
if sPropertyName = 'First Row Column Name' then
pConn.ConnectionProperties.Item(i).Value := False;
if sPropertyName = 'Column Names' then
pConn.ConnectionProperties.Item(i).Value := 'OrgCode,SaleNo,'+
'XsDate,TranType,PageNo,LnNo,ClkID,ClkCode,PackType,PackCode,PluID,PluCode'
if sPropertyName = 'Text Qualifier' then
pConn.ConnectionProperties.item(i).Value := '''';
if sPropertyName = 'Number Of Column' then
pConn.ConnectionProperties.Item(i).Value := iNumberOfColumn;
if sPropertyName = 'Text Qualifier Col Mask: 0=no,1=yes,e.g. 0101' then
pConn.ConnectionProperties.Item(i).Value := '1111';
if sPropertyName = 'Max characters per delimited column' then
pConn.ConnectionProperties.Item(i).Value := 8000;
if sPropertyName = 'Blob Col Mask: 0=no,1=yes,e.g. 0101' then
pConn.ConnectionProperties.Item(i).Value := '0000';
end;
未知原因,请赐教,如有VB,VC,JAVA,Ruby语言的转化源代码也不胜感激。或者给出connectionproperties的所有
属性,我去Miscosoft的帮助中没有找到,亦或有知道的给我发个链接或者地址都行,多谢~
procedure TForm1.Button1Click(Sender: TObject);
begin
self.ADOQuery1.SQL.Text := 'select * from test';
self.ADOQuery1.Open;
self.ADOQuery1.SaveToFile('C:\TEST.TXT');
end;
要是不特殊也不用定义文本文件格式了呀...我是实现普通与远程监控之间的表导入导出操作。同时生成本地txt文件,就因为要特殊格式,所以才定义...
僵哥,能说的详细点么?或者举例给说明下。我用的是DTSFLATFILE,ODBC文本可以直接导成固定格式的TXT文件么?
我需要自己定义一些格式,但报错,昨天研究觉得是文本文件打开或者写的过程有问题,你能给我举个简单
例子或者代码我参考下么
begin
self.ADOQuery1.SQL.Text := 'select * from test';
self.ADOQuery1.Open;
self.ADOQuery1.SaveToFile('C:\TEST.TXT');
end;
exec master..xp_cmdshell 'bcp "数据库名.dbo.表名" out "d:\DT.txt" -c -t , -S"服务器名" -T'
将数据导出到DT.txt文本文件中, 在目标数据库执行
exec master..xp_cmdshell 'bcp "数据库名.dbo.表名" in "d:\DT.txt" -c -t , -S"服务器名" -T'
将DT.txt文本文件中数据导入到新的数据库中