ADO with password data connection, query a recordset, execute a SQL statement

xiaoxiao2021-03-06  57

In the SQL statement, the Like condition is used in deiphi: .... Like "% aabbcc%" // unit udataModule

Interface

Uses Controls, Sysutils, Classes, DB, AdoDB, Windows, Forms

type TDataModule1 = class (TDataModule) ADOConnection1: TADOConnection; dsDataSet: TADODataSet; ADOQuery1: TADOQuery; procedure DataModuleCreate (Sender: TObject); private {Private declarations} public ConnOK: boolean; {Public declarations} end;

Var DataModule1: TdataModule1; Function OpenSQL (S: String; Query: Tadodataset): Integer; Function DOSQL (S: String; Query: Tado Query): Boolean; Impletionation

{$ R * .dfm}

procedure TDataModule1.DataModuleCreate (Sender: TObject); var SQL, pwd: string; begin // connection ADO try pwd: = 'deliSerial'; SQL: = 'Provider = Microsoft.Jet.OLEDB.4.0; Data Source =' extractfilepath (paramstr (0)) 'SerialInfo.mdb' '; Persist Security Info = False;' 'Jet OLEDB: Database Password = "' pwd '"'; ADOConnection1.Connected: = false; ADOConnection1.ConnectionString: = Sql; adoconnection1.connected: = true; connok: = true; Except connok: = false; end;

function OpenSQL (s: string; query: TADODataSet): integer; var old_Cursor: TCursor; begin old_Cursor: = screen.cursor; screen.cursor: = crSQLWait; try try with query do begin close; commandtext: = s; open; result : = query.Recordcount; End; Except results: = 0; end; finally screen.cursor: = OLD_CURSOR; END;

function DoSQL (s: string; query: TADOQuery): boolean; var old_Cursor: TCursor; begin result: = true; old_Cursor: = screen.cursor; screen.cursor: = crSQLWait; try try with query do begin close; SQL.Clear SQL.Add (s); Exceql; End; Except results: = false; end; finally screen.cursor: = OLD_CURSOR; END; END;

转载请注明原文地址:https://www.9cbs.com/read-109216.html

New Post(0)