Query2.Close;
        with StringGrid1 do begin
          m := RowCount;
          for j := 1 to m -3 do begin
            ReDM := Cells[1,j];
            ReSL := Cells[5,j];
            Query2.Sql.Clear;
            Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+',)');
          end;
        end;
      Query2.ExecSQL;
老是提示出错,错在什么地方?正确的做法是什么?

解决方案 »

  1.   


                Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values (''''+QuotedStr(BM)+'''',''''+QuotedStr(ReDM)+'''',''''+QuotedStr(ReSL)+'''')');
      

  2.   

    试试:
    Query2.Close;
            with StringGrid1 do begin
              m := RowCount;
              for j := 1 to m -3 do begin
                ReDM := Cells[1,j];
                ReSL := Cells[5,j];
                Query2.Sql.Clear;
                Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+',)');                  Query2.ExecSQL;
              end;
            end;
      

  3.   

    改成:
     Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+QuotedStr(BM)+''','''+QuotedStr(ReDM)+''','''+QuotedStr(ReSL)+''',)');
      

  4.   

    改为: 
     Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+QuotedStr(BM)+','+QuotedStr(ReDM)+','+QuotedStr(ReSL)+')');
      

  5.   

    我是DELPHI6,可以通过,你试试看:Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('+''''+QuotedStr(BM)+''''+','+''''+QuotedStr(ReDM)+''''+','+''''+QuotedStr(ReSL)+''''+',)');
      

  6.   

    //写代码的时候仔细一点,SQL语句间是用分号分隔不是逗号~~
    //调试的时候如果有错就把SQL语句放到数据库查询分析器中调试下先~~
    //那里过了,Delphi里才能过~~begin
      Query2.Close;
      Query2.SQL.Clear;
      with StringGrid1 do begin
        M := RowCount;
        for J := 1 to RowCount - 3 do begin
          ReDM := Cells[1, J];
          ReSL := Cells[5, J];
          Query2.SQL.Add(Format(
    'Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values (%s,%s,%s);', [
            QuotedStr(BM), QuotedStr(ReDM), QuotedStr(ReSL)]));
        end;
      end;
      try
        Query2.ExecSQL;
      except
        { TODO : 异常处理 }
      end;
    end;
      

  7.   

    showmessage(sql.text)看看你的SQL语句对不对
      

  8.   

    with StringGrid1 do begin
              m := RowCount;               //假如m=3
              for j := 1 to m -3 do begin  //不运行
                ReDM := Cells[1,j];
                ReSL := Cells[5,j];
            //  Query2.Sql.Clear;  在这里有什么用??反正都是执行的最后一条
            //  或者把后面的query2.execsql提到前面来
            //  Query2.Sql.text:='Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+BM+''','''+ReDM+''','''+ReSL+'''';//我喜欢用text
            //query.sql.execsql;  上面3句建议同时使用
              end;
            end;
      //    Query2.ExecSQL;
      

  9.   

    更正
    with StringGrid1 do begin
      m := RowCount;
      for j := 1 to m -3 do begin
        ReDM := Cells[1,j];
        ReSL := Cells[5,j];
        Query2.Close;
        Query2.Sql.Clear;
        Query2.Sql.Add('Insert Into PHDEK_CL.db (DEH,CLDM,SL) Values ('''+QuotedStr(BM)+''','''+QuotedStr(ReDM)+''','''+QuotedStr(ReSL)+''')');
        Query2.ExecSQL;
      end;
    end;