小
小天
Unregistered / Unconfirmed
GUEST, unregistred user!
function AppendTable(TableName:string;CDS:TTable):boolean;
var table1:TTable;
i:integer;
f:boolean;
begin
f:=true;
try
table1:=TTable.create(nil);
table1.DatabaseName:='MyDatabase';
table1.TableName:=TableName;
table1.open;
table1.First;
CDS.Open;
CDS.Last;
while not table1.Eof do
begin
CDS.Append;
for i:=0 to table1.FieldCount-1 do
if (table1.fields.isnull)or(string(table1.fields.AsVariant)='')
then if not table1.fields.isnull
then CDS.fields.AsVariant:=''
else CDS.fields.AsString:=''
else CDS.fields.AsVariant:=table1.fields.AsVariant;
CDS.Post;
table1.Next;
end;
CDS.Close;
table1.close;
table1.free;
except
f:=false;
end;
result:=f;
end;
功能:把一个database中的table的内容追加到另一个database中相同结构的table中
出错位置:for i:=0 to table1.FieldCount-1 do
if (table1.fields.isnull)or(string(table1.fields.AsVariant)='')
then if not table1.fields.isnull
then CDS.fields.AsVariant:=''
else CDS.fields.AsString:=''
else CDS.fields.AsVariant:=table1.fields.AsVariant;
出错估计:是不是AsVariant对空字段等无法判断或无法转换?
紧急求援:谁能帮我优化一下出错处的代码?
var table1:TTable;
i:integer;
f:boolean;
begin
f:=true;
try
table1:=TTable.create(nil);
table1.DatabaseName:='MyDatabase';
table1.TableName:=TableName;
table1.open;
table1.First;
CDS.Open;
CDS.Last;
while not table1.Eof do
begin
CDS.Append;
for i:=0 to table1.FieldCount-1 do
if (table1.fields.isnull)or(string(table1.fields.AsVariant)='')
then if not table1.fields.isnull
then CDS.fields.AsVariant:=''
else CDS.fields.AsString:=''
else CDS.fields.AsVariant:=table1.fields.AsVariant;
CDS.Post;
table1.Next;
end;
CDS.Close;
table1.close;
table1.free;
except
f:=false;
end;
result:=f;
end;
功能:把一个database中的table的内容追加到另一个database中相同结构的table中
出错位置:for i:=0 to table1.FieldCount-1 do
if (table1.fields.isnull)or(string(table1.fields.AsVariant)='')
then if not table1.fields.isnull
then CDS.fields.AsVariant:=''
else CDS.fields.AsString:=''
else CDS.fields.AsVariant:=table1.fields.AsVariant;
出错估计:是不是AsVariant对空字段等无法判断或无法转换?
紧急求援:谁能帮我优化一下出错处的代码?