超简单问题,(可惜我不会。。。)为什么我不能用query控件插入记录?(100分)

  • 主题发起人 四界辰砂
  • 开始时间

四界辰砂

Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码如下:
var
Count:integer;
LongMax,LatiMax:Double;
TempStr1,TempStr2,TempStr3:String;
begin
if(Edit1.Text<>'')and(Edit2.Text<>'')then
begin
LongMax:=StrtoFloat(Edit1.Text);
LatiMax:=StrtoFloat(Edit2.Text);
Query1.Close;
Query1.SQL.Add('INSERT INTO SecondX(Name,Number,Longi,Lati) VALUES:)Name,:Number,:Longi,:Lati)');
for Count:=1 to 200 do
begin
with Query1 do
begin
ParamByName('Name').asString:='Record'+inttoStr(Count);
ParamByName('Number').Asinteger:=Count;
ParamByName('Longi').AsFloat:=LongMax/10;
ParamByName('Lati').AsFloat:=LatiMax/10;
ExecSql;
end;//end with
end;//end for
end;//end if
其主要的目的是产生一系列的纪录,作为系统测试用,但是delphi老是提示我“invalid use of
keyword token:INSERT Line Number:2”这里到底有什么问题呢?还请各位大侠指教。
 
在Query1.Close;之后加入
Query1.sql.clear;
注意参数的名称,不要与数据库的保留字一样,Number不知道是不是sql server的
保留字。改改试试。
 
可以单独使用一个 TQuery;

“INSERT INTO SecondX(Name,Number,Longi,Lati)
VALUES:)Name,:Number,:Longi,:Lati)”
作为静态SQL使用!!!!
 
同意楼上所说的
var
Count:integer;
LongMax,LatiMax:Double;
TempStr1,TempStr2,TempStr3:String;
begin
if(Edit1.Text<>'')and(Edit2.Text<>'')then
begin
LongMax:=StrtoFloat(Edit1.Text);
LatiMax:=StrtoFloat(Edit2.Text);
Query1.Close;
Query1.sql.clear;
Query1.SQL.Add('INSERT INTO SecondX(Name,Number,Longi,Lati) VALUES:)Name1,:Number1,:Longi1,:Lati1)');
for Count:=1 to 200 do
begin
with Query1 do
begin
ParamByName('Name1').asString:='Record'+inttoStr(Count);
ParamByName('Number1').Asinteger:=Count;
ParamByName('Longi1').AsFloat:=LongMax/10;
ParamByName('Lati1').AsFloat:=LatiMax/10;
ExecSql;
end;//end with
end;//end for
end;//end if
 
顶部