Difference between revisions of "TDBGrid"
From Free Pascal wiki
Jump to navigationJump to search(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TDBGrid}} | ||
+ | |||
'''TDBGrid''' [[image:tdbgrid.png]] 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]]. | '''TDBGrid''' [[image:tdbgrid.png]] 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]]. | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
// configure connection with database | // configure connection with database | ||
SQLConnector1.ConnectorType := 'MySQL 5.1'; | SQLConnector1.ConnectorType := 'MySQL 5.1'; | ||
Line 24: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | == See also == |
+ | |||
* [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]] | * [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]] | ||
+ | * [[TdxDBGridController]] | ||
* [[TStringGrid]] | * [[TStringGrid]] | ||
+ | * [[Grids Reference Page]] | ||
+ | * [[TDataSource]] | ||
{{LCL Components}} | {{LCL Components}} | ||
− | |||
− |
Latest revision as of 18:07, 4 January 2023
│
English (en) │
français (fr) │
日本語 (ja) │
русский (ru) │
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.
// configure connection with database
SQLConnector1.ConnectorType := 'MySQL 5.1';
SQLConnector1.HostName := 'MyServer';
SQLConnector1.DatabaseName := 'MyDBName';
SQLConnector1.UserName := 'MyName';
SQLConnector1.Password := 'MyPass';
// connect SQLConnector, SQLTransaction, DataSource, SQLQuery and DBGrid
SQLTransaction1.Database := SQLConnector1;
SQLQuery1.Transaction := SQLTransaction1;
DataSource1.DataSet := SQLQuery1;
DBGrid1.DataSource := DataSource1;
// setup query to get (at least) two fields from MyTable
SQLQuery1.SQL := 'SELECT * FROM MyTable';
// setup grid with result from query
DBGrid1.Columns[0].Title.Caption := 'Name';
DBGrid1.Columns[0].FieldName := 'fieldDescription';
DBGrid1.Columns[1].Title.Caption := 'Description';
DBGrid1.Columns[1].FieldName := 'fieldName';
// Open result and show in grid
SQLQuery1.Open();
See also