Q&A

  • Invalid parameter error ....
어디서 부터 질문을 해야 할지 몰라서 소스를 통체로 올립니다. ㅡㅡ...
Ini file에 있는 내용을 호출 하여 DB table 을 생성 후 생성된
필드에 값을 넣어 주려 합니다.

디버그시 qry.sql.add 의 string 변수에 값은 잘 들어 갑니다.

근데 퀘리실행만 시키면 Invalid Parameter 가 뜨네요...( *** ~ ***) 에서요~

paradox DB 를 만들어서 사용했고, Tool 은 delphi 6 쓰고 있습니다.

오류 원인을 밝혀 주시면 감사하겠지만, 그게 아니더라도

( *** ~ ***)에  Qry 사이에 있는 for문에 문제가 있는지...아니면

Invalid Parameter error 가 왜,언제 발생하는지 알고 싶습니다.

답변 주시면 감사하겠습니다.



//******************************************************************************
// DB table Insert
//******************************************************************************
procedure TFrm_rms.Btn_InsertClick(Sender: TObject);
var
        Cnt, Rec_cnt, AllCount, SelCount, i, j : Integer;
        F, FF : system.text; //TextFile;
        S,FileName, FileDir, Insert_Fname, Bar_copy, status_copy : string;
        DBTable, strComplete : String;
        tbl    : TTable;
        F_cnt, p, q, r, k :  Integer;
        Envini : Tinifile;
        bar1, F_value, rec_1, S_temp, S_last : String;

begin
    listbox1.Clear;   //
    if FileListBox1.Items.Count = 0  then
    begin
       ShowMessage( 'Please Select insert to File .');
       Exit;
    end;
    if DirectoryExists(ProcDir + '\DATA') then
    begin
      RemoveDir(ProcDir + '\DATA');
    end;

    CreateDir(ProcDir + '\DATA');
    DBName := ProcDir + '\DATA';
    if (not DirectoryExists(ProcDir + '\DATA\TEMPDB1.DB')) then
    begin
      // == 없으면 생성.
      DBTable := 'TEMPDB1';
      DataBaseCreate(Application, DBName, DBTable, ttParadox);
    end;

    AllCount := FileListBox1.Items.Count;
    SelCount := FileListBox1.SelCount;
    FileDir  := FileListBox1.Directory;
    Rec_cnt := 0; // 건당 레코드 건수

    for i := 0 to AllCount - 1 do begin
     if (FileListBox1.Selected[i]) then begin
       FileName := FileDir + '\' + FileListBox1.Items.Strings[i];
       system.AssignFile(F,FileName);
       {$i-}
       Reset(F);
       Cnt := 0;  // 토탈 레코드 건수
       while not eof(F) do
       begin
         Readln(F,S);
         Cnt := Cnt + 1;
         Rec_Cnt := Rec_Cnt + 1;
       end;
       CloseFile(F);
       Gauge1.MaxValue := Cnt;
       system.AssignFile(F, FileName);
       Reset(F);     //  원본 파일 오픈
      
       Envini := TiniFile.Create(inifile);
       F_cnt := EnvIni.ReadInteger('Database Field','Field Count',0);

       rec_1 := EnvIni.ReadString('Data Format','Record Format','');
       if F_cnt =1 then
       begin
           bar1 := EnvIni.ReadString('Field Value','Barcode','');
       end
       else
       begin
           bar1 := EnvIni.ReadString('Field Value','Barcode','');
           for k :=1 to F_cnt -1 do begin
            Listbox1.Items.Add(EnvIni.ReadString('Field Value','Field'+ IntToStr(k),'') )

           end;
       end;
       while not eof(F) do
       begin
          Readln(F,S);

         if F_cnt = 1 then
         begin
            Frm_env.Delete_comma(bar1);
            Bar_copy := Copy(S,StrToInt(s1),StrToInt(s2));
            status_copy := '0';

            Query1.DatabaseName := ProcDir + '\DATA';
            Query1.Close;
            Query1.SQL.Clear;
            Query1.SQL.Add('Insert into TEMPDB1 Values ( ');
            Query1.SQL.Add(' '''+Bar_copy +''', ');
            Query1.SQL.Add(' '''+status_copy +''') ');
            Query1.ExecSQL;
            Query1.Close;
          end
          else
          begin
            if rec_1 = 'F' then
            begin
                Frm_env.Delete_comma(bar1);
                Bar_copy := Copy(S,StrToInt(s1),StrToInt(s2));
                status_copy := '0';

                Query1.DatabaseName := ProcDir + '\DATA';
                Query1.Close;
                Query1.SQL.Clear;
                Query1.SQL.Add('Insert into TEMPDB1 Values ( ');
                Query1.SQL.Add(' ''' + Bar_copy +''', ');
                for p := 0 to ListBox1.Items.Count - 1 do begin
                    Query1.SQL.Add(' ''' + Copy(S,StrToInt(copy(ListBox1.Items[p], 1 , Pos(',',ListBox1.Items[p])-1)),StrToInt(copy     (ListBox1.Items[p],Pos(',',ListBox1.Items[p])+1 , Length(ListBox1.Items[p])-Pos(',',ListBox1.Items[p]))))+ ''', ');
                end;
                Query1.SQL.Add(' '''+ status_copy +''') ');
                Query1.ExecSQL;
                Query1.Close;
            end;

*****************************************************************************************

            if rec_1 = 'V' then
            begin
                Frm_env.Delete_comma(bar1);
                Bar_copy := Copy(S,StrToInt(s1),StrToInt(s2));
                status_copy := '0';

                Query1.DatabaseName := ProcDir + '\DATA';
                Query1.Close;
                Query1.SQL.Clear;
                Query1.SQL.Add('Insert into TEMPDB1 Values ( ');
                Query1.SQL.Add(' '''+ Bar_copy +''', ');



                for q := 1 to F_cnt do begin
                    if q <> F_cnt then
                    begin
                        S_temp := '';
                        for r := 1 to Length(S) do begin
                            if Copy(S,r,1) = ',' then
                            begin
                                break;
                            end
                            else
                            begin
                                S_temp :=S_temp + Copy(S,r,1);
                            end;

                        end;
                        S := Copy(S,Length(S_temp) + 2 , Length(S) - Length(S_temp) + 1);
                        Query1.SQL.Add(' '''+ S_temp +''', ');
                    end;
                end;
                Query1.SQL.Add(' '''+ S +''', ');
                Query1.SQL.Add(' '''+ status_copy +''') ');
                Query1.ExecSQL;                              
            //-----------------> invalid parameter error !!!!!!!!!                          
                Query1.Close;
            end;

************************************************************************************************

         end;      

         Gauge1.progress := Gauge1.progress + 1


       end;    // while end


          CloseFile (F) ;
          CloseFile (FF) ;
          Edit3.Text := Copy('             ',1, 13-Length(IntToStr(Rec_cnt))) + IntToStr(Rec_Cnt);
       {$i-}
     end;      // if end
    
    end;       // for end


    Envini.Free;
    
    strComplete := 'Total ' + IntToStr(SelCount) +'(' + InttoStr(Rec_Cnt) + ') job to be completed.';
    ShowMessage(strComplete);
    StatusBar1.SimpleText := 'HELP : Please Select Rms3000 Log File.';
    FileListBox1.Items.Clear;



end;

0  COMMENTS