为什么我的程序运行后会变成这样?(100分)

  • 主题发起人 主题发起人 nancyxi
  • 开始时间 开始时间
N

nancyxi

Unregistered / Unconfirmed
GUEST, unregistred user!
实现读入文本文件,然后存入数据库表中,下面是我的代码,编译运行没有问题,但是向
数据库提交的却是如下的结果,而不是我希望的那样,读一个文本文件后向表中提交一行
数据:
1.
insert into csbxTest2(AxialForce,ConfiningPressure,PorePressure,Temperatur,Length,
Wave,VerticalScale,HorizontalScale,HorizontalDelay) values(' 5.000000E+0',' 4.000000E+1',' 0.000000E+0',' 3.000000E+1',' 5.105000E+4',' S1','','','')
2.
insert into csbxTest2(AxialForce,ConfiningPressure,PorePressure,Temperatur,Length,
Wave,VerticalScale,HorizontalScale,HorizontalDelay) values(' 5.000000E+0',' 4.000000E+1',' 0.000000E+0',' 3.000000E+1',' 5.105000E+4','','','','')
.......

程序代码:
valuelist:=TStringList.Create;
if OpenDialog1.Execute then
valuelist.LoadFromFile(OpenDialog1.FileName);
sqlString:='';
for I:=0 to valuelist.Count-1 do
begin
if valuelist.Names='Axial Force' then
AxialForce:=valuelist.ValueFromIndex
else if valuelist.Names='Confining Pressure' then
ConfiningPressure:=valuelist.ValueFromIndex
else if valuelist.Names='Pore Pressure' then
PorePressure:=valuelist.ValueFromIndex
else if valuelist.Names='Temperature' then
Temperature:=valuelist.ValueFromIndex
else if valuelist.Names='Length' then
Length:=valuelist.ValueFromIndex
else if valuelist.Names='Wave' then
Wave:=valuelist.ValueFromIndex
else if valuelist.Names='Vertical Scale' then
VerticalScale:=valuelist.ValueFromIndex
else if valuelist.Names='Horizontal Delay' then
HorizontalDelay:=valuelist.ValueFromIndex
else if valuelist.Names='Horizontal Scale' then
HorizontalScale:=valuelist.ValueFromIndex;
sqlString:='insert into csbxTest2(AxialForce,ConfiningPressure,PorePressure';
sqlString:=sqlString+',Temperatur,Length,Wave,VerticalScale,HorizontalScale';
sqlString:=sqlString+',HorizontalDelay) values('''+AxialForce+''','''+ConfiningPressure+''',';
sqlString:=sqlString+''''+PorePressure+''','''+Temperature+''','''+Length+''','''+Wave+''',';
sqlString:=sqlString+''''+VerticalScale+''','''+HorizontalScale+''','''+HorizontalDelay+''')';
DataModule2.ADOQuery1.Close;
DataModule2.ADOQuery1.SQL.clear;
DataModule2.ADOQuery1.SQL.add(sqlString);
DataModule2.ADOQuery1.ExecSQL;
end;
valuelist.free;
 
有什么不对吗?
 
运行一个文件如下结果:
AxialForce ConfiningPressure PorePressure Temperatur Length Wave VerticalScale HorizontalScale HorizontalDelay
------------ ----------------- ------------ ------------ ------------ ---- ------------- --------------- ---------------
5.000000E+0 2.000000E+1 0.000000E+0
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4

5.000000E+0
5.000000E+0 2.000000E+1
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4
5.000000E+0 2.000000E+1 0.000000E+0 3.000000E+1 5.105000E+4

(所影响的行数为 11 行)

一个文件是应该向表中提交一行数据的呀。
 
把sqlString的赋值放在end;的后面试试
 
3X
问题解决是循环的问题:)
 
后退
顶部