学习 SQL 语句 - Select(1): 指定表
2021/4/30 19:29:00
本文主要是介绍学习 SQL 语句 - Select(1): 指定表,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
学习 SQL 语句 - Select(1): 指定表
//选择 country 表中的所有字段 SELECT * FROM country {虽然 SQL 并不区分大小写, 但应习惯把关键字大写}
本例效果图:
代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; Button2: TButton; DBGrid1: TDBGrid; DataSource1: TDataSource; ADODataSet1: TADODataSet; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {查看数据库 dbdemos.mdb 中的 country 表} procedure TForm1.Button1Click(Sender: TObject); begin ADODataSet1.Close; ADODataSet1.CommandText := 'SELECT * FROM country'; ADODataSet1.Open; end; {查看数据库 dbdemos.mdb 中的 customer 表} procedure TForm1.Button2Click(Sender: TObject); begin with ADODataSet1 do begin Close; CommandText := 'SELECT * FROM customer'; Open; end; end; {控件关联、连接数据库: dbdemos.mdb} procedure TForm1.FormCreate(Sender: TObject); var mdbFile: string; begin {获取 CodeGear 共享安装的数据文件: dbdemos.mdb 的路径} mdbFile := GetEnvironmentVariable('COMMONPROGRAMFILES'); {C:\Program Files\Common Files} mdbFile := mdbFile + '\CodeGear Shared\Data\dbdemos.mdb'; ADODataSet1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + mdbFile + ';Persist Security Info=False'; DBGrid1.DataSource := DataSource1; DataSource1.DataSet := ADODataSet1; end; end.
窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 407 ClientWidth = 645 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 0 Top = 35 Width = 645 Height = 372 Align = alClient DataSource = DataSource1 TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'Tahoma' TitleFont.Style = [] end object Panel1: TPanel Left = 0 Top = 0 Width = 645 Height = 35 Align = alTop Caption = 'Panel1' TabOrder = 1 object Button1: TButton Left = 16 Top = 4 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 97 Top = 4 Width = 75 Height = 25 Caption = 'Button2' TabOrder = 1 OnClick = Button2Click end end object DataSource1: TDataSource DataSet = ADODataSet1 Left = 184 Top = 112 end object ADODataSet1: TADODataSet CursorType = ctStatic Parameters = <> Left = 232 Top = 184 end endposted on 2009-05-28 01:40 万一 阅读(5723) 评论(7) 编辑 收藏
这篇关于学习 SQL 语句 - Select(1): 指定表的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南
- 2025-01-03图像文字理解,OCR、大模型还是多模态模型?PalliGema2在QLoRA技术上的微调与应用
- 2025-01-03混合搜索:用LanceDB实现语义和关键词结合的搜索技术(应用于实际项目)
- 2025-01-03停止思考数据管道,开始构建数据平台:介绍Analytics Engineering Framework
- 2025-01-03如果 Azure-Samples/aks-store-demo 使用了 Score 会怎样?
- 2025-01-03Apache Flink概述:实时数据处理的利器
- 2025-01-01使用 SVN合并操作时,怎么解决冲突的情况?-icode9专业技术文章分享
- 2025-01-01告别Anaconda?试试这些替代品吧
- 2024-12-31自学记录鸿蒙API 13:实现人脸比对Core Vision Face Comparator
- 2024-12-31自学记录鸿蒙 API 13:骨骼点检测应用Core Vision Skeleton Detection