熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

Delphi開發經驗技巧:使用SQL語句保存數據

2022-06-13   來源: Delphi編程 
    ——此文章摘自《Delphi開發經驗技巧寶典》定價 特價 購買>>http://tracklinktechcn/?m_id=dangdang&a_id=A&l=&l_type= width= height= border= nosave>

    本例通過SQL語句把員工的信息存入到數據庫中主要代碼如下
    procedure TFrmTransBtnSaveClick(Sender: TObject);
    var
      ADOQuery: TADOQuery;
      SQL: string;
    begin
      ADOQuery := TADOQueryCreate(nil);
      ADOQueryConnection := ADOConn;
      SQL :=
       Insert Into TB_Worker(NumberNameOldSexTelePhoneDepartMentJoinDate) ;
      SQL := SQL +
       Values(:Number:Name:Old:Sex:TelePhone:DepartMent:JoinDate);
      ADOQuerySQLAdd(SQL);
      with ADOQueryParameters do
      begin
       ParamByName(Number)Value := Trim(EDNumberText);
       ParamByName(Name)Value := Trim(EDNameText);
       ParamByName(Old)Value := StrToIntDef(Trim(EdOldText) );
       if CBxSexText = then
        ParamByName(Sex)Value :=
       else
         ParamByName(Sex)Value := ;
         ParamByName(TelePhone)Value := Trim(EdTelePhoneText);
         ParamByName(DepartMent)Value := Trim(CBXdePartMentText);
         ParamByName(JoinDate)Value := DTPJoinDateDate;
      end;
      try
       ADOQueryExecSQL;
      finally
       ADOQueryFree;
      end;
      ADODataSetRequery();
      GBxListEnabled := False;
      BtnSaveEnabled := False;
      BtnNewEnabled := True;
      ShowMessage(數據保存成功);
    end;


From:http://tw.wingwit.com/Article/program/Delphi/201311/24925.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.