5,390
社区成员
发帖
与我相关
我的任务
分享
procedure TFormHouse.btnSelectClick(Sender: TObject);
var
sSQL:string;
begin
sSQL := 'Select * From TB_House Where 1 > 0 ';
if Trim(edt1.Text) <> '' then
sSQL := sSQL + ' and HouseNum = ' + QuotedStr(edt1.Text) + '';
if Trim(edt2.Text) <> '' then
sSQL := sSQL + ' and HouseInfo = ' + QuotedStr(edt2.Text) + '';
with Query do
begin
Connection := TDBConnector.Instance.Connection; //执行到这出错
SQL.Text := sSQL;
Open;
ds1.DataSet := Query;
dbgrdh1.DataSource := ds1;
end;
end;
procedure TAccessConnector.StartConnect;
begin
if not Assigned(Connection) then
Connection := TADOConnection.Create(nil);
with Connection do
begin
LoginPrompt := False;
ConnectionString := Format(ACCESSCONN_STR, [DBName, DBPassword]); //DBName, DBPaddword读取配置文件
//ACCESSCONN_STR为常量: ACCESSCONN_STR = 'Provider=Microsoft.Jet.OLEDB.4.0;Password="";'+
'Data Source=%s;Persist Security Info=True;'+
'Jet OLEDB:Database Password=%s';
Open;
FConnected := True;
end;
end;