delphi 數據庫小技巧

#資料庫設置
[DBLINK]
ServiceName=10.13.65.201
USERID=ics
PASSWORD=ics
database=ICS_PROD
#------------------------------
#ServiceName=10.112.65.250
#USERID=sa
#PASSWORD=sa
#database=msa

 

讀取ini文件

procedure TForm1.setconn;
var
   myfile:TIniFile;
   servername,uid,pwd:string;
begin
    myfile :=TIniFile.Create(extractfiledir(application.ExeName) + '/CONFIG.INI');
    try
    servername:=myfile.ReadString('DBLINK','ServiceName','');
    uid:=myfile.ReadString('DBLINK','USERID','');
    pwd:=myfile.ReadString('DBLINK','PASSWORD','');
    database:=myfile.ReadString('DBLINK','database','');
    finally
      myfile.Free;
end;

if ADOConnection1.Connected = true then
    ADOConnection1.Connected := false;
  with ADOConnection1 do begin
    LoginPrompt := false;
    ConnectionString :='Provider=SQLOLEDB.1;Password='+pwd+';Persist Security Info=True;User ID='+uid+';Initial Catalog='+database+';Data Source='+servername+'';
  end;
end;

 

split功能實現

 

function TForm1.split(s, s1: string): TStringList;
begin
  Result:=TStringList.Create;
  while Pos(s1,s)>0 do
  begin
     Result.Add(Copy(s,1,Pos(s1,s)-1));
     Delete(s,1,Pos(s1,s));
  end;
  Result.Add(s);
end;

 

日期的格式化

_date:=inttostr(strtoint(copy(FormatdateTime('yyyy/MM/dd',date),1,4))+1);

 

-----動態數組與賦值

setlength(myArr,100);

myArr[count-1]:=tempvalue

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章