delphi新手。。想做个小程序试试,结果遇到点问题。。想请高手指教下。
在写where 情况下,可以把所有的数据从单选题表移动到考卷表,用着完全没问题。。
想设置下条件,产生一个随机数进行随机选题。。结果无法将数据传过去。表内格式没问题,数据也正常,no用的accsee自动编号。
相关代码如下:
p:=(Random(2)+1); with ADOQuery1 do
begin Close;
Sql.Clear;
Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= "1"');
// Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= '''+inttostr(p)+''' ') ;
Execsql;
end;
在写where 情况下,可以把所有的数据从单选题表移动到考卷表,用着完全没问题。。
想设置下条件,产生一个随机数进行随机选题。。结果无法将数据传过去。表内格式没问题,数据也正常,no用的accsee自动编号。
相关代码如下:
p:=(Random(2)+1); with ADOQuery1 do
begin Close;
Sql.Clear;
Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= "1"');
// Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= '''+inttostr(p)+''' ') ;
Execsql;
end;
即可。如果no是整数类型
Select wt,daa,dab,dac from 单选题 where no= "1"' Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= "1"');
// Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= '''+inttostr(p)+''' ') ;------------------------------------
//把双引号"" 改为''
//no字段是字符型时,语句如下
Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= ''1''');//no字段是数值型时,语句如下
Sql.Add('insert into 考卷 (wt,daa,dab,dac) Select wt,daa,dab,dac from 单选题 where no= 1');
原因是数据表的问题。。把no换成别的任意项都可以。。估计是access对no的问题吧。