{ Initialize the variables needed to run the query }
 
with ListBox1 do
if ItemIndex = -1 then
raise Exception.Create(’Can’’t Run Query: No Alias Selected’)
else
strAlias := Items.Strings[ItemIndex];
 
with ListBox2 do
if ItemIndex = -1 then
raise Exception.Create(’Can’’t Run Query: No Table Selected’)
else
strTable := Items.Strings[ItemIndex];
 
with ListBox3 do
if ItemIndex = -1 then
begin
if ComboBox1.ItemIndex > Ord(soNocondition) then
raise Exception.Create(’Can’’t Run Query: No Field Selected’)
else
strField := ’’;
end
else
strField := Items.Strings[ItemIndex];
 
if (Edit1.Text = ’’) and
(ComboBox1.ItemIndex > Ord(soNoCondition)) and
(ComboBox1.ItemIndex < Ord(soBlank)) then
raise Exception.create(’Can’’t Run Query: No Search Value Entered’)
else
strValue := Edit1.Text;
 
{ See if the field being search is a string field. If so, then pad the
quote string with quotation marks; otherwise, set it to a null value. }
 
if strField <> ’’ then
with Table1.FieldByName(strField) do
if (DataType = ftString) or (DataType = ftMemo) then
strQuote := ’"’ else
strQuote := ’’;
 
{ Construct the WHERE clause of the query based on the user’s choice
in Type. }
 
case etSQLOps(ComboBox1.ItemIndex) of
soNoCondition: strWhere := ’’;
soEqual: strWhere := strField + ’ = ’ + strQuote + strValue+ strQuote;
soNotEqual: strWhere := strField + ’ <> ’ + strQuote + strValue +
strQuote;
soLessThan: strWhere := strField + ’ < ’ + strQuote + strValue +
strQuote;
soLessEqual: strWhere := strField + ’ <= ’ + strQuote + strValue +
strQuote;
soMoreThan: strWhere := strField + ’ > ’ + strQuote + strValue +
strQuote;
soMoreEqual: strWhere := strField + ’ >= ’ + strQuote + strValue +
strQuote;
soStartsWith: strWhere := strField + ’ LIKE ’ + strQuote +
strValue + ’%’ + strQuote;
soNoStartsWith: strWhere := strField + ’ NOT LIKE ’ + strQuote +
strValue + ’%’ + strQuote;
soEndsWith: strWhere := strField + ’ LIKE ’ + strQuote +
’%’ + strValue + strQuote;
soNoEndsWith: strWhere := strField + ’ NOT LIKE ’ +
strQuote + ’%’ + strValue + strQuote;
soContains: strWhere := strField + ’ LIKE ’+ strQuote+’%’+ strValue
+ ’%’ + strQuote;
soNoContains: strWhere := strField + ’ NOT LIKE ’ + strQuote + ’%’
+ strValue + ’%’ + strQuote;
soBlank: strWhere := strField + ’ IS NULL’;
soNotBlank: strWhere := strField + ’ IS NOT NULL’;
end;
 
if ComboBox1.ItemIndex = Ord(soNoCondition) then
strQuery := ’SELECT * FROM "’ + strTable + ’"’
else if Table1.FieldByName(strField).DataType = ftString then
strQuery := ’SELECT * FROM "’ + strTable + ’" t WHERE t.’ + strWhere
else
strQuery := ’SELECT * FROM "’ + strTable + ’" t WHERE t.’ + strWhere;
 
{ Create an instance of the browser form. }
frmQuery := TResultForm.Create(Application);

转载于:https://www.cnblogs.com/JTeacher/archive/2012/11/19/2776915.html

delphi使用SQL的教程7相关推荐

  1. [SQL基础教程] 1-5 表的删除和更新

    [SQL基础教程] 1-5 表的删除和更新 表的删除 语法 DROP TABLE <表名>; 法则 1-12 删除的表无法恢复 表定义的更新 语法 ALTER TABLE<表名> ...

  2. 链接3: SQL语句教程

    链接:   SQL语句教程 - 由范例学习SQL语句 https://www.1keydata.com/cn/sq 首页:

  3. sql基础教程和mysql基础教程_书评「SQL基础教程(第2版)」| 你应该知道的基础知识点梳理·上...

    写在前面关于这本书:SQL的基础教程,可以使你在SQL的学习中轻松实现从0到1的过程,循序渐进地掌握SQL的基础知识和技巧.对于零基础来说非常友好,看完能够迅速上手SQL. 关于本文:一篇对这本书的知 ...

  4. sql基础教程mysql_SQL基础教程(第2版)笔记整理

    花了一段时间把SQL基础教程(第2版)看完,并把笔记整理好. 数据定义语言(Data Define Language) 数据操作语言(Data Manipulation Language) 数据控制语 ...

  5. [SQL基础教程]1-4 SQL 表的创建

    [SQL基础教程]1-4 SQL 表的创建 创建数据库 语法 CREATE DATABASE <数据库名称> // example CREATE DATABASE shop; 创建表 语法 ...

  6. sql基础教程亚马逊_针对Amazon,Apple,Google的常见SQL面试问题

    sql基础教程亚马逊 SQL is used in a wide variety of programming jobs. It's important to be familiar with SQL ...

  7. 写给运营同学和初学者的SQL入门教程

    作者简介 多肉,饿了么资深python工程师.曾在17年担任饿了么即时配送众包系统的研发经理,这篇文章最早的版本就诞生于那段时间,目前负责配送相关业务系统的整体稳定性建设.个人比较喜欢c和python ...

  8. delphi连接sql server的字符串2011-10-11 16:07

    delphi连接sql server的字符串2011-10-11 16:07 一.delphi连接sql server 放一个连接组件 ADOConnection, 其它组件TADODataSet,T ...

  9. 《SQL 入门教程》示例数据库

    文章目录 Oracle 示例表 示例数据 创建索引 删除对象 MySQL 示例表 示例数据 创建索引 删除对象 Microsoft SQL Server 示例表 示例数据 创建索引 删除对象 Post ...

最新文章

  1. 《人工智能北京共识》发布, 智源研究院成立伦理与安全研究中心
  2. MATLAB实战系列(十一)-多种群遗传算法的函数优化算法(附MATLAB代码)
  3. Windows如何读取Linux,Linux下读取Windows注册表
  4. [老老实实学WCF] 第八篇 实例化
  5. php html转为pdf文件,php使用wkhtmltopdf实现html转pdf
  6. mysql mydump还原_用mydump对所有数据库进行备份,还原具体案例
  7. 按钮自动居中布局_CSS布局技巧
  8. 存量电力系统_RCR新文:中国电力基础设施发展的物质存量和流量
  9. 背包问题:从给定的无序、不重复的数组 A 中,取出N个数,使其相加和为M
  10. express+mongodb制作简单的文章发布系统(一)之环境的搭建
  11. imooc数据结构探险-栈篇 栈应用括号匹配二 由群友启发改良james_yuan老师算法
  12. 《流程的永恒之道:工作流及BPM技术的理论、规范、模式及最佳实践》书籍导读
  13. CASA方法估算NPP(IDL+ENVI)
  14. Ubuntu安装Ruby
  15. Qt--探讨.exe程序加密
  16. 恶意软件沙盒规避技术与原理详解
  17. uniapp消息推送
  18. 【Lua】【协同程序】【coroutine】知识点详解
  19. REST ful风格总结(在逍遥子的基础上~只供自己简单总结,详情请看原文)
  20. 沧浪之水清兮,可以濯吾缨;沧浪之水浊兮,可以濯吾足

热门文章

  1. 20230210组会总结
  2. Android系统启动顺序(按下power键后所做的的工作)
  3. 7-3 懒虫小鑫 (10 分)(C语言版)
  4. CentOS7内网穿透(公网访问内网)SakuraFrp-frpc配置(从0开始)
  5. 华为虚拟机服务器关闭,虚拟机服务器重启命令行
  6. 论文阅读 End-to-End Multi-View Fusion for 3D Object Detection in Lidar Point Clouds
  7. java将实体数据导出到excel,压缩,删除等一系列~
  8. 选择小红书素人笔记推广有什么好处?
  9. 安装专业版Pycharm并破解激活
  10. jdbc读取mysql数据库_Ecplise 中利用 JDBC 连接 Mysql 数据库读取数据