<dfn id="is4kg"></dfn>
  • <ul id="is4kg"></ul>
  • <abbr id="is4kg"></abbr>
  • <ul id="is4kg"></ul>
    <bdo id="is4kg"></bdo>
    以文本方式查看主題

    -  曙海教育集團論壇  (http://www.hufushizhe.com/bbs/index.asp)
    --  Delphi程序設計  (http://www.hufushizhe.com/bbs/list.asp?boardid=76)
    ----  幾個delphi書中沒提過的數據庫問題與我的疑惑和心得(一起討論)  (http://www.hufushizhe.com/bbs/dispbbs.asp?boardid=76&id=2570)

    --  作者:wangxinxin
    --  發布時間:2010-12-14 11:16:27
    --  幾個delphi書中沒提過的數據庫問題與我的疑惑和心得(一起討論)

    1,ADOConnection和ADOTable在delphi中的使用

    ADOConnection和ADOTable在delphi中像許多書中教的那樣設置好連接上數據庫(我用的SQLServer),運行沒有問題。然后我修改,目的是可以修改連接數據庫而不用在delphi中修改ADOConnection的ConnectionString屬性,還不出現連接對話框。

    修改步驟:將LoginPrompt設置為false,將ConnectionString屬性清空,添加連接代碼

    conStr:=\'Provider=SQLOLEDB.1;Password=1982072019;User ID=sa;Initial Catalog=StorageManagement;Data Source=10.16.99.175\';
      try
        loginForm.tempADOConnection.ConnectionString :=conStr;
        loginForm.tempADOConnection.Connected := true;
      except
        messagedlg(\'數據庫連接有誤!!請檢查DataConfig.XML\',mtConfirmation,[mbOk],0);
        Application.Terminate;
      end;

    這樣程序運行起來,連接數據庫是沒有問題的。但出現的問題是在dlephi中ADOTable控件是不能連接表的,因為ConnectionString屬性沒有值。報錯為“無效的授權說明”。如何既能在delphi中使用ADOConnection和ADOTable控件,又可以不出現那個討厭的連接對話框。

    2,在delphi中使用sql語句。

    因為sql語句中給字符串賦值需要用雙引號,而delphi中用單引號括起字符串,我使用遇到了一些問題。我試驗的結果是delphi中用兩個單引號代替sql語句中的雙引號。不知道對不對?

    具體如何使用,我還是不太清楚。

    3,在delphi 7.0中使用ADOQuery的返回結果,書中介紹使用Params[\'xxxx\'].AsString;

    我使用后報錯,但有一個光盤的程序這樣使用沒有報錯。我使用的是Parameters[\'xxxx\'],也使用不了.AsString

    4,原代碼:
    ====================================================================
    if canInsert then
      begin
        with allDataModule.AQ_OtherMaterielOut do
        begin
          Close;
          SQL.Clear;
          SQL.Text:=\'insert otherMaterielOut(materielID,amount) values (:insertID,:insertAmount,)\';
          Parameters[0].Value:=myMateriel;
          Parameters[1].Value:=myAmount; 
          ExecSQL;
        end;
        with allDataModule.AQ_OtherMaterielStock do
        begin
          Close;
          SQL.Clear;
          SQL.Text:=\'update otherMaterielStock set amount=amount-:updateAmount where materielID=:updateID\';
          Parameters[0].Value:=myAmount;
          Parameters[1].Value:=myMateriel;
          ExecSQL;
        end;
        materielOutForm.Close;
      end;

    在這段代碼之后
    with allDataModule.AQ_OtherMaterielOut do
        begin
          Close;
          SQL.Clear;
          SQL.Text:=\'update otherMaterielStock set amount=amount-:updateAmount where materielID=:updateID\';
          Parameters[0].Value:=myAmount;
          Parameters[1].Value:=myMateriel;
          ExecSQL;
        end;

    不能使用allDataModule自動顯示可以使用的控件列表功能,但我強加上后面的代碼仍然可以使用。怎么回事?