procedure TForm1.BitBtn1Click(Sender: TObject);
var
i:integer;
fname:string;
h:Textfile;
ps:byte;
a,b:string;
iPos,j:integer;
Fld:array[0..17] of string;
begin
for i:=0 to lb_file.Items.count-1 do
begin
fname:= DirectoryListBox1.Directory+''+lb_file.items.Strings[i];
//showmessage(fname);
// CreateAWSinsert(fname);
if FileExists(fname) then
begin
assignfile(h,fname);
reset(h);
readln(h,a);
while not Eof(h) do
begin
iPos := Pos('#',a);
if iPos <> 0 then //"|"이 있는 라인 쯕 실제 레코드를 찾아서 들어간다.
begin
j:=0;
while (a<>'=') and (length(a)>0) do
begin
if (length(a) =0) then //"="이라는 문자를 만나야지만..1개의 레코드 끝이다.
begin
readln(h,b);
j:=0;
a := a + b;
end else
begin
ps:=pos('#',a);
fld[j]:=copy(a,1,ps-1); //여기서 데이터를 처리하던가 아님 배열등으로...
a:=copy(a,ps+1,length(a));
j:=j+1;
end;
end;
//showmessage('data input');
//테이블에 입력
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.ADD('select * from aws_min');
Query1.SQL.ADD('where stn_id=fld[0] and tm_fc=fld[1]');
Query1.Open;
showmessage('aaa');
if Query1.RecordCount<>0 then
begin
showmessage('update');
with Query1 do
begin
close;
DatabaseName:='weather';
SQL.Clear;
SQL.Add('Update aws_min');
SQL.Add('Set stn_id=fld[0]');
SQL.Add('Set tm_fc=fld[1]');
SQL.Add('Set ft_lat=fld[2]');
SQL.Add('Set ft_lon=fld[3]');
SQL.Add('Set ft_hig=fld[4]');
SQL.Add('Set wd=fld[5]');
SQL.Add('Set ws=fld[6]');
SQL.Add('Set ta=fld[7]');
SQL.Add('Set rn=fld[8]');
SQL.Add('Set st1=fld[9]');
SQL.Add('Set st2=fld[10]');
SQL.Add('Set cc=fld[11]');
SQL.Add('Set hc=fld[12]');
SQL.Add('Set dc=fld[13]');
SQL.Add('Set bc15=fld[14]');
SQL.Add('Set bc60=fld[15]');
SQL.Add('Set wtd=fld[16]');
SQL.Add('Set wts=fld[17]');
SQL.Add('Where stn_id=fld[0] and tm_fc=fld[1]');
//if Prepared = false then Prepare;
ExecSQL;
end;
end
else
begin
with Query1 do
begin
showmessage('Insert');
close;
DatabaseName:='weather';
SQL.Clear;
SQL.Add('Insert Into aws_min');
SQL.Add('(stn_id,tm_fc,ft_lat,ft_lon,ft_hig,wd,ws,ta,rn,st1,st2,cc,hc,dc,bc15,bc60,wtd,wts) Values');
SQL.Add('(fld[0],fld[1],fld[2],fld[3],fld[4],fld[5],fld[6],fld[7],fld[8],fld[9],fld[10],fld[11],fld[12],fld[13],fld[14],fld[15],fld[16],fld[17])');
//if Prepared = false then Prepare;
ExecSQL;
end;
end;
end;
end;
readln(h,a);
end;
closefile(h);
end;
end;
======================================================================
입력이나 수정 루틴을 만나면 에러가 나네여..
고수님들 좀 봐주세여....ㅠㅠ
스키마파일을 만들어 사용하면 간단히 해결됩니다.