Database

Delete a User from adatabase in Sql Server 2000

Delete a User from adatabase in Sql Server 2000 procedure TForm1.Button1Click(Sender: TObject); begin ADOCommand1.CommandText := ‘Use DataBaseName’; ADOCommand1.Execute; ADOCommand1.CommandText := ‘Exec SP_DropUser ‘ + QuotedStr(‘Username’); ADOCommand1.Execute; end;

Database

Add a user into a database in Sql Server 2000

Add a user into a database in Sql Server 2000 procedure TForm1.Button1Click(Sender: TObject); begin ADOCommand1.CommandText := ‘Use DataBaseName’; ADOCommand1.Execute; ADOCommand1.CommandText := ‘Exec SP_AddUser ‘ + QuotedStr(‘Username’); ADOCommand1.Execute; end;

Database

Connect To Sql Server 2000

Connect To Sql Server 2000 procedure TForm1.Button1Click(Sender: TObject); begin ADOConnection1.ConnectionString := ‘Server=Hostname;DataBase=DatabaseName’; ADOConnection1.Open(‘UserName’, ‘Password’); ADOConnection1.Connected := True; end; {* For Any Information Mail Me * Mail : Mostafa@Touska.Co.ir0

Database

Add a User’s Login in Sql Server 2000

Add a User’s Login in Sql Server 2000 procedure TForm1.Button1Click(Sender: TObject); begin ADOConnection1.Connected := True; ADOCommand1.CommandText := ‘Exec SP_AddLogin ‘ + QuotedStr(‘UserName’) + ‘,’ + QuotedStr(‘Password’) + ‘,’ + QuotedStr(‘Database Name’) + ‘,’ + QuotedStr(‘English’) […]

Database

Adapt DateTime values for SQL-Server or Access formats

{——————————————————————— Dieser Tip ist als Verbesserung zum ursprünglichen Artikel http://www.swissdelphicenter.ch/de/showcode.php?id=1423 gedacht. Die folgende Funktionen wandeln einen DateTime Wert (unabhنngig vom eingestelltem Datumsformat) in einen für den SQL-Server verstنndlichen String um. ———————————————————————- Please also take a […]

Database

Scroll within a DBGrid

Here is tip how to scroll DBGrid private OldGridProc: TWndMethod; procedure GridWindowProc(var Message: TMessage); //… procedure TForm1.FormCreate(Sender: TObject); begin OldGridProc := DBGrid1.WindowProc; DBGrid1.WindowProc := GridWindowProc; end; procedure TForm1.GridWindowProc(var Message: TMessage); var Pos: SmallInt; begin OldGridProc(Message); […]

Database

Make a HTML and TXT report component

Make a HTML and TXT report component unit LittleReport; interface uses Windows, Messages, SysUtils, Classes, DB, Graphics; const FAuthor = ‘Simone Di Cicco’; FVersion = ‘1.0’; type TLittleReport = class(TComponent) protected FDataSet: TDataSet; FWidth: Integer; […]

Database

Create a Dataset lookup field at runtime

example: create lookup field (string, size: 50) at runtime with TStringField.Create(YourDataSet) do begin FieldName := ‘FieldName’; FieldKind := fkLookup; DataSet := YourDataSet; Name := DataSet.Name + FieldName; KeyFields := ‘YourKeyFields’; LookupDataSet := YourLookupDataSet; LookupKeyFields := […]

Database

Add a Row Number in your DBGrid

1. create new blank field in dbgrid 2. rename the title with ‘No’ 3. put this code in OnDrawColumncell 4. Now your Grid has a row number procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; […]

Database

Create an Access Database (2)

Create an Access Database (2) uses ComObj; procedure TForm1.Button1Click(Sender: TObject); var AccessApp: Variant; begin AccessApp := CreateOleObject(‘Access.Application’); AccessApp.NewCurrentDatabase(‘c:\111.mdb’); AccessApp := Unassigned; end;

Database

Color a specific (conditional) cell in a DBGrid

Color a specific (conditional) cell in a DBGrid procedure TFRM_Main.DBG_MainGetCellParams(Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean); begin if (Field.AsString = ‘0’) and (Field.FullName = ‘LoadingAttn’) then begin Background := $00E69B00; AFont.Color […]

Database

create an Access Database From Delphi

uses ComObj; procedure TForm1.Button1Click(Sender: TObject); var AccessApp: Variant; begin AccessApp := CreateOleObject(‘Access.Application’); AccessApp.NewCurrentDatabase(‘c:\111.mdb’); AccessApp := Unassigned; end;

Database

create a table including an AutoInc field (ADO/MSSQL)?

// Erzeugt eine Tabelle mit dem Namen MYTABLENAME, mit den Spalten ID, // MYTEXT1, MYTEXT2. // (Der Name der ID Spalte kann natürlich frei gewählt werden.) // ID ist der Primärschlüssel der Tabelle. Er ist ein Integer, der sich // automatisch für jede Zeile // der Tabelle erhöht. ID wird nie doppelt vorkommen. // MYTEXT1 und 2 sind vom Typ String. // Ich verwende die ADOConnection um mit Jet 4.0 auf eine Access- // datenbank (*.mdb) zuzugreifen. // Der Syntax ist MSSQL, wenn ihr das für PHP oder so verwenden wollt, // muss man das ein bissel umformulieren 😉 // Creates a Table called MYTABLENAME with a unique identifier called // “ID”. ID increases with every new row automatically. MYTEXT1 and 2 // are Strings. Name the colums as you want to. // I used the ADOConnection to access a MS-Access Database (*.mdb) // via Jet 4.0. // The Syntax is MSSQL, you have to transform it to use it in PHP or so. uses AdoDB; var q: TAdoQuery; db: TAdoConnection; begin // Initialize db here q := TADOQuery.Create(nil); q.Connection := db; q.Close; q.SQL.Clear; q.SQL.Add(‘Create Table MYTABLENAME (ID COUNTER PRIMARY KEY, MYTEXT1 String, MYTEXT2 String);’); q.Prepared := True; try q.ExecSQL; except end; q.Free; end;