Database

Get Rid Of the Annoying SQL Wait Cursor

{ Simply place this one line of code in the OnCreate event of the form that is showing the annoying SQL Wait cursor… } procedure TForm1.FormCreate(Sender: TObject); begin Screen.Cursors[crSQLWait] := Screen.Cursors[crHourGlass]; // or whatever cursor […]

Database

Convert a ADO Recordset to XML and the reverse way

Convert a ADO Recordset to XML and the reverse way unit ADOXMLUnit; interface uses Classes, ADOInt; function RecordsetToXML(const Recordset: _Recordset): string; function RecordsetFromXML(const XML: string): _Recordset; implementation uses ComObj; { Example: … Memo1.Lines.Text:=RecordsetToXML(ADOQuery1.Recordset); … } […]

Database

Read a BlobStream with TADOQuery from an AccessDB

Read a BlobStream with TADOQuery from an AccessDB function GetBlobStream(Query: TADOQuery): TMemoryStream; begin result := TMemoryStream.Create; // You must connect to AccessDB first. // See: Query.Connection, TADOConection or Query.ConnectString // Send SQL command Query.Active := […]

Database

Create database on local MS SQL Server 2000

Create database on local MS SQL Server 2000 procedure CreateDatabase(WindowsSecurity: Boolean; Username, Password: String); var ConnectionString: String; CommandText: String; begin if WindowsSecurity then ConnectionString := ‘Provider=SQLOLEDB.1;’ + ‘Integrated Security=SSPI;’ + ‘Persist Security Info=False;’ + ‘Initial […]

Database

Create tables on MS SQL Server 2000

Create tables on MS SQL Server 2000 procedure TLocal.CreateTables(WindowsSecurity: Boolean; Username, Password: String); var ConnectionString: String; begin if WindowsSecurity then ConnectionString := ‘Provider=SQLOLEDB.1;’ + ‘Integrated Security=SSPI;’ + ‘Persist Security Info=False;’ + ‘Initial Catalog=test’ else ConnectionString […]

Database

Load a jpeg file into a blob field using SQL

Load a jpeg file into a blob field using SQL procedure TForm1.Button1Click(Sender: TObject); var ms: TMemoryStream; begin if OpenPictureDialog1.Execute then begin ms := TMemoryStream.Create; try ms.LoadFromFile(OpenPictureDialog1.FileName); with Query1 do begin with SQL do begin Clear; […]

Database

Convert a Query into a Table

Convert a Query into a Table unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables; type TForm1 = class(TForm) Button1: TButton; Query1: TQuery; DataSource1: TDataSource; DBGrid1: […]

Database

Create Tables Detial/Master in Sql Server 2000 With Code

Create Tables Detial/Master in Sql Server 2000 With Code procedure TForm1.Button1Click(Sender: TObject); begin ADOCommand1.CommandText := ‘Create Table MasterTable ‘ + ‘(FieldName Primary Key);’; ADOCommand1.Execute; ADOCommand1.CommandText := ‘Create Table Detailtable ‘ + ‘(Fieldname Primary Key Refrenced […]

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;