dbcombobox数据库录入,怎样使它能把所得的内容不重复(50分)

  • 主题发起人 主题发起人 newhorse
  • 开始时间 开始时间
N

newhorse

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是数据库录入,每次录入都有可能是以前已经输入的。所以使用dbcombobox方便些
所以在ITEMS加入某字段内容: 怎样使它能把所得的内容不重复呢?
table1.first;
dbcombobox1.items.clear;
while not table1.eof do
begin
combobox1.items.add(table1.fieldbyname('field1').asstring);
table1.next;
end;
 
建一个唯一索引。
 
不能这样做,我的目的是要输入这样以前曾经录的内容,如果唯一索引,不能
录入重复的内容。
 
例如,name 字段中有
A
B
C
B
A
我要使ITEMS中只有
A
B
C
 
用TQuery或ADOQuery
设SQL为 Select YourFieldname from yourtable group by yourfieldname
这是最简单的,如果你还是要用TTabel的话:
var
s:String;
begin
table1.first;
dbcombobox1.items.clear;
while not table1.eof do
begin
s:=table1.fieldbyname('field1').asstring;
if ComboBox1.Itmes.Indexof(s)<0 then
combobox1.items.add(s);
table1.next;
end;
end;
 
同意杜宝。
sql语句中还有一个是去处重复记录的语句。好象是Distict,记不清了。你可以查查关系数据库的资料。
 
楼上说得不错
mysql='select distict * from table';
 
后退
顶部