TDBGrid: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TDBGrid
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **TDBGrid**  is a visual component that displays tabular data from database contents through means of a [[TDataSet]] derivative like a [[TSQLQuery]]. The TDBGrid component is available from the [[Data Controls tab]] of the [[Component Palette]]. | |
| 2 | + | ||
| 3 | + | ``` pascal | |
| 4 | + | // configure connection with database | |
| 5 | + | SQLConnector1.ConnectorType := 'MySQL 5.1'; | |
| 6 | + | SQLConnector1.HostName := 'MyServer'; | |
| 7 | + | SQLConnector1.DatabaseName := 'MyDBName'; | |
| 8 | + | SQLConnector1.UserName := 'MyName'; | |
| 9 | + | SQLConnector1.Password := 'MyPass'; | |
| 10 | + | // connect SQLConnector, SQLTransaction, DataSource, SQLQuery and DBGrid | |
| 11 | + | SQLTransaction1.Database := SQLConnector1; | |
| 12 | + | SQLQuery1.Transaction := SQLTransaction1; | |
| 13 | + | DataSource1.DataSet := SQLQuery1; | |
| 14 | + | DBGrid1.DataSource := DataSource1; | |
| 15 | + | // setup query to get (at least) two fields from MyTable | |
| 16 | + | SQLQuery1.SQL := 'SELECT * FROM MyTable'; | |
| 17 | + | // setup grid with result from query | |
| 18 | + | DBGrid1.Columns[0].Title.Caption := 'Name'; | |
| 19 | + | DBGrid1.Columns[0].FieldName := 'fieldDescription'; | |
| 20 | + | DBGrid1.Columns[1].Title.Caption := 'Description'; | |
| 21 | + | DBGrid1.Columns[1].FieldName := 'fieldName'; | |
| 22 | + | // Open result and show in grid | |
| 23 | + | SQLQuery1.Open(); | |
| 24 | + | ``` | |
| 25 | + | ||
| 26 | + | ## See also | |
| 27 | + | ||
| 28 | + | - [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]] | |
| 29 | + | - [[TdxDBGridController]] | |
| 30 | + | - [[TStringGrid]] | |
| 31 | + | - [[Grids Reference Page]] | |
| 32 | + | - [[TDataSource]] | |
| 33 | + | ||
| 34 | + | --- | |
| 35 | + | *From the Free Pascal wiki, page "TDBGrid", as it stood on 2023-01-04 after a change by Five, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
