1. The use of ADOConnection and ADOTable in delphi
ADOConnection and ADOTable are set up to connect to the database (I use SQLServer) in delphi as taught in many books, and there is no problem in running. Then I modified it, the purpose is to modify the connection database without modifying the ConnectionString property of the ADOConnection in delphi, and the connection dialog box does not appear.
Modification steps: Set LoginPRompt to false, clear the ConnectionString property, and add the connection code
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('The database connection is incorrect!! Please check DataConfig.xml',mtConfirmation,[mbOk],0);
application.Terminate;
end;
In this way, there is no problem connecting to the database when the program runs. But the problem that occurs is that in dlephi ADOTable control cannot connect to tables because the ConnectionString property has no value. The error is reported as "Invalid authorization statement". How to use ADOConnection and ADOTable controls in delphi, and avoid the annoying connection dialog box.
2. Use sql statements in delphi.
Because the sql statement requires double quotes to assign values to strings, while the strings are enclosed in single quotes in delphi, I encountered some problems using them. The result of my experiment is that two single quotes are used in delphi instead of double quotes in the sql statement. Don't know if it's right?
I still don't know exactly how to use it.
3. Use ADOQuery in delphi 7.0 to return results. The book introduces the use of Params['xxxx'].AsString;
I reported an error after using it, but there is a CD program that uses it in this way without an error. I'm using Parameters['xxxx'], and I can't use .AsString
4. Original code:
===================================================================== =========================
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 materialID=:updateID';
Parameters[0].Value:=myAmount;
Parameters[1].Value:=myMateriel;
ExecSQL;
end;
materialOutForm.Close;
end;
After this code
with allDataModule.AQ_OtherMaterielOut do
Begin
Close;
SQL.Clear;
SQL.Text:='update otherMaterielStock set amount=amount-:updateAmount where materialID=:updateID';
Parameters[0].Value:=myAmount;
Parameters[1].Value:=myMateriel;
ExecSQL;
end;
The function of automatically displaying the control list that can be used cannot be used with allDataModule, but I forced the code behind it to still work. What's going on?