1,ADOConnection和ADOTable在delphi中的使用
ADOConnection和ADOTable在delphi中像許多書中教的那樣設(shè)置好連接上數(shù)據(jù)庫(kù)(我用的SQLServer),運(yùn)行沒有問(wèn)題。然后我修改,目的是可以修改連接數(shù)據(jù)庫(kù)而不用在delphi中修改ADOConnection的ConnectionString屬性,還不出現(xiàn)連接對(duì)話框。
修改步驟:將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ù)庫(kù)連接有誤!!請(qǐng)檢查DataConfig.XML',mtConfirmation,[mbOk],0);
Application.Terminate;
end;
這樣程序運(yùn)行起來(lái),連接數(shù)據(jù)庫(kù)是沒有問(wèn)題的。但出現(xiàn)的問(wèn)題是在dlephi中ADOTable控件是不能連接表的,因?yàn)镃onnectionString屬性沒有值。報(bào)錯(cuò)為“無(wú)效的授權(quán)說(shuō)明”。如何既能在delphi中使用ADOConnection和ADOTable控件,又可以不出現(xiàn)那個(gè)討厭的連接對(duì)話框。
2,在delphi中使用sql語(yǔ)句。
因?yàn)閟ql語(yǔ)句中給字符串賦值需要用雙引號(hào),而delphi中用單引號(hào)括起字符串,我使用遇到了一些問(wèn)題。我試驗(yàn)的結(jié)果是delphi中用兩個(gè)單引號(hào)代替sql語(yǔ)句中的雙引號(hào)。不知道對(duì)不對(duì)?
具體如何使用,我還是不太清楚。
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)加上后面的代碼仍然可以使用。怎么回事?