Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Databasoberoende
|
Kategori: Databaser
Inlagt: 2005-07-28
Läst: 1645
Inlagt av: Staffan Berg
|
Beskrivning |
Dessa databaskopplingar är så nära oberoende av databas du kan komma. Exemplena körs genom ADO-teknik och fungerar med kopplingar mot DBase, Access och Paradox.
|
Kod |
procedure RunSQL(sSQL : String); var qrySQL : TADOQuery; begin qrySQL := TADOQuery.Create(Application); qrySQL.Connection := adoConnection; qrySQL.SQL.Clear; qrySQL.SQL.Text := sSQL; qrySQL.ExecSQL; qrySQL.Free; end; ******************************************************************************* procedure GetRecords(var qryField : TADOQuery; sSQL : String; LockType : TADOLockType = ltReadOnly); begin if qryField = Nil then begin qryField := TADOQuery.Create(Application); qryField.CursorType := ctOpenForwardOnly; qryField.Connection := adoConnection; end; qryField.Close; qryField.LockType := LockType; qryField.SQL.Clear; qryField.SQL.Add(sSQL); qryField.Open; end; ******************************************************************************* Example of use for RunSQL: ............................................................................... var sSQL : String; begin sSQL := 'insert into TB_Log (UserId,UserName) values ("My User Id","My User Name")'; RunSQL(sSQL); ............................................................................... Example of use for GetRecords: ............................................................................... var qrySetup : TADOQuery; begin GetRecords(qrySetup,'select * from TB_Setup',ltOptimistic); if qrySetup['IsRegistered'] then begin ShowMessage('Your are a Registered user') else ShowMessage('Your are NOT a Registered user'); //DO NOT forget to free it when done. qrySetup .Free; ............................................................................... Another example for the use for GetRecords: ............................................................................... var qryUsers : TADOQuery; begin GetRecords(qryUsers,'select * from TB_Users',ltOptimistic); while NOT qryUsers.Eof do begin if qryUsers['UserName'] = 'Abdulaziz' then ShowMessage('It's me!!!'); qryUsers.Next; end; qryUsers.Free;
|
|
|