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

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

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

    1,ADOConnection和ADOTable在delphi中的使用

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

    修改步驟:將LoginPrompt設(shè)置為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(\'數(shù)據(jù)庫連接有誤!!請檢查DataConfig.XML\',mtConfirmation,[mbOk],0);
        Application.Terminate;
      end;

    這樣程序運(yùn)行起來,連接數(shù)據(jù)庫是沒有問題的。但出現(xiàn)的問題是在dlephi中ADOTable控件是不能連接表的,因?yàn)镃onnectionString屬性沒有值。報(bào)錯(cuò)為“無效的授權(quán)說明”。如何既能在delphi中使用ADOConnection和ADOTable控件,又可以不出現(xiàn)那個(gè)討厭的連接對話框。

    2,在delphi中使用sql語句。

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

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

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

    我使用后報(bào)錯(cuò),但有一個(gè)光盤的程序這樣使用沒有報(bào)錯(cuò)。我使用的是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自動(dòng)顯示可以使用的控件列表功能,但我強(qiáng)加上后面的代碼仍然可以使用。怎么回事?