cmd1.CommandText :=('insert into kckmenu(货号,仓库,库存数量,库存金额,库存单价) values ('''+StringGrid1.Cells [1,i]+''','''+StringGrid1.Cells [5,i]+''','''+StringGrid1.Cells [4,i]+''','+StringGrid1.Cells [7,i]+','+StringGrid1.Cells [6,i]+')');
cmd1.Execute ;

cmd1.CommandText:='update kckmenu set 库存数量=库存数量+'''+StringGrid1.Cells [4,i]+''' where 货号='''+StringGrid1.Cells [1,i]+'''';
cmd1.Execute;
都出现','附近有语法错误啊
请高手指点

解决方案 »

  1.   

    把你的SQL放到数据库的查询里试试就知道哪错误了。
      

  2.   

    Sql语句最好Format一下,这么看着太费劲了,肯定是那块儿多了或少了个单引号
      

  3.   

    1.Delphi里面的双引号''在执行后转换成单引号'
    2.出错的地方修改为'',''
      

  4.   

    cmd1.CommandText:='update kckmenu set 库存数量=库存数量+'+StringGrid1.Cells [4,i]+' where 货号='''+StringGrid1.Cells [1,i]+'''';
    cmd1.Execute;
      

  5.   

    cmd1.CommandText :=('insert into kckmenu(货号,仓库,库存数量,库存金额,库存单价) values ('''+StringGrid1.Cells [1,i]+''','''+StringGrid1.Cells [5,i]+''','+StringGrid1.Cells [4,i]+','+StringGrid1.Cells [7,i]+','+StringGrid1.Cells [6,i]+')');
    cmd1.Execute ;
      

  6.   

    cmd1.CommandText:='update kckmenu set [库存数量]='''+StringGrid1.Cells [4,i]+'''  where [货号]='''+StringGrid1.Cells [1,i]+'''';
      

  7.   

    StringGrid1.Cells [4,i]这个可能含有‘,’,想办法处理掉。库存数量=库存数量+'''+StringGrid1.Cells [4,i]+'''
    这个语句也不对:数据类型是
    数据=数据+字符
    我觉得应该是
    '库存数量=库存数量+'+StringGrid1.Cells [4,i]+.....
    红线部门一定要确保没有“,”的符合数字规范的字符。
      

  8.   

    问一个课外话题,csdn的可用积分怎么获得啊?
      

  9.   

    showmessage(cmd1.CommandText);
    自己看下不就清楚了
      

  10.   

    ('''+StringGrid1.Cells [1,i]+
    应该是
    (''''+StringGrid1.Cells [1,i]+作为字符串传进去的
      

  11.   

    使用 
    try...except  在except里面将 运行时的 sql执行语句抛出。查看一下不就完了。
    try
        //失败才跳进 except里执行
    except on e:Exception do
    ShowMessage(e.Message);
    end;
      

  12.   

    改为:
    cmd1.CommandText :=('insert into kckmenu(货号,仓库,库存数量,库存金额,库存单价) values ('''+StringGrid1.Cells [1,i]+''','''+StringGrid1.Cells [5,i]+''','''+StringGrid1.Cells [4,i]+''','''+StringGrid1.Cells [7,i]+''','''+StringGrid1.Cells [6,i]+''')');
    cmd1.Execute ;

    cmd1.CommandText:='update kckmenu set 库存数量=库存数量+'''+StringGrid1.Cells [4,i]+''' where 货号='''+StringGrid1.Cells [1,i]+''' ';
    cmd1.Execute;
    你再试试
      

  13.   

    cmd1.commandText:=format('insert into kckmenu(货号,仓库,库存数量,库存金额,库存单价) values (%s,%s,%f,%f,%f)',[quotedstr(StringGrid1.Cells [1,i),quotedstr(StringGrid1.Cells [5,i]),StringGrid1.Cells [4,i],StringGrid1.Cells [7,i],StringGrid1.Cells [6,i]]);
    cmd1.Execute;
    cmd1.CommandText:=format('update kckmenu set 库存数量=库存数量+%f where 货号=%s',[StringGrid1.Cells [4,i],quotedstr(StringGrid1.Cells [1,i])]);
    cmd1.Execute;
    用这种方法测试下。
      

  14.   

    把赋值给 cmd1.CommandText:= 后面的语句 赋值给 String  ,然后把String ShowMessage出来,就知道结果了 ;
      

  15.   

    cmd1.CommandText :=('insert into kckmenu(货号,仓库,库存数量,库存金额,库存单价) values ('''+StringGrid1.Cells [1,i]+''','''+StringGrid1.Cells [5,i]+''','''+StringGrid1.Cells [4,i]+''','+StringGrid1.Cells [7,i]+','+StringGrid1.Cells [6,i]+')');
    cmd1.Execute ;引用用错了~
      

  16.   

    对于ACCESS:
    字符和时间类型要用"''"(2个单引号),数字和逻辑不要单引号。记住这个。