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自动显示可以使用的控件列表功能,但我强加上后面的代码仍然可以使用。怎么回事?
没有相关教程
|