我想搜索表中 年份=2000 学期=上 部门=机电 的记录,请问如何实现
要求得到的结果可以修改,谢谢,谢谢。
query1.close;
query1.sql.clear;
query1.sql.add(select * from table1 where 年份=2000 and 学期=上 and 部门=机电);
query1.open;
用TQuery嘛:
SQL := Select * from table1 where 年份=2000 and 学期=上 and 部门=机电;
设置它的RequestLive为True
对呀,如上写就可以了。
用Filter呀
filtered=true
filter= 年份=2000 and 学期=上 and 部门=机电
table1.filter=年份=2000 and 学期=上 and 部门=机电
table1.filtered:=true;
Table1.Filtered := true;
Table1.Filter := 年份=2000 and 学期=上 and 部门=机电;
table1.open;
table1.filter:=年份=2000 and 学期=上 and 部门=机电;
table1.filtered:=true;
table1.disablecontrols;
table1.first;
while not table1.eof do
begin
if table1.fieldbyname(年份).value=2000 and
table1.fieldbyname(学期).value=上 and
table1.fieldbyname(部门).value=机电 then
.............//do what you want to do .
table1.next;
end;
table1.enablecontrols;
str1:= form3.edit3 .text;
str2:= form3.combobox;
str3:= form3.table1.FieldByName(部门).asstring;
form3.table3.filter:=年份= + + str1 and ....
用locate()查詢到記錄后再edit.
table1.filtered:=false;
table1.filter:=年份=2000 and 学期=上 and 部门=机电;
table1.filtered:=true;
-----------------
table1.locate(年份,2000,[]);//详细请看帮助
你如果非要用table的话, str前后都要加引号
建议你改用query
我的这句话form3.table3.filter:=年份= + +str1 + and +上下半年= + +str2+ and + 部门= + +str3;编译通过了,
但执行时出现filter语句不正确的被终止,请帮忙分析一下。
with Table do
Locate(年份;学期;部门, VarArrayOf([2000, 上, 机电]), [loPartialKey]);
with Table do
Locate(年份;学期;部门, VarArrayOf([2000, 上, 机电]), [loPartialKey]);
楼上的方法可以用,但是不知道对不对,现在的Delphi的入门书教的都是些没有的东西,又骗钱有坑人。
给你举个例子吧,你要付我网费:)
在窗体上放置一个Query1,和UpdateSql1
然后Query1连接数据库,按以下设置Query1的属性:
CacheUpdate设置为True
UpdateObject设置为UpdateSql1
然后Query1去查询数据,用UpdateSql1去修改数据,
可以在UpdateSql1控件上点鼠标右键,选择UpdateSql Editor项可以自动写SQL语句,就可以完成你的要求了
实际上Table完全可以实现你的要求,只是你的基本功太差,好好练练吧。
如果还是不会用的话,明天12点以后,我的QQ79383778,如果你现在在的话,也可以call我
不会啊,用Query做怎么不能修改呢!只要把RequestLive属性设为True就可以了。
你用Table做的话所有的查询是在你的前台完成的而不是后台,效率会非常低下。
with query do
begin
Close;
SQL.Add(select * from Table);
SQL.Add(where 年份 = "2000"‘);
SQL.Add(and 学期 = "上");
SQL.Add(and 部门 = “机电”’);
Open;
end;
肯定没错!