• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphi使用SQL的教程7

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

{ 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);


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
您的第一个Delphi程序(Hello World) - pchmonster发布时间:2022-07-18
下一篇:
ubuntu20.04 安装 MATLAB2018b发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap