with Qry_Employee,ComboBox1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Employee'); //T_Employee'包含name,salary两字段
Open;
Clear;
First;
while not eof do
begin
Items.Add(FieldByName('name').AsString);
Edit1.Text:=FieldByName('salary').asstring;
Next;
end;
end;
例如我在ComboBox1中选择员工名称“张三”,我想在旁边一个Edit1文本框中显示
张三的工资,但是我这个代码显示的结果始终是最后一个员工的薪水,请问如何修改??
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Employee'); //T_Employee'包含name,salary两字段
Open;
Clear;
First;
while not eof do
begin
Items.Add(FieldByName('name').AsString);
Edit1.Text:=FieldByName('salary').asstring;
Next;
end;
end;
例如我在ComboBox1中选择员工名称“张三”,我想在旁边一个Edit1文本框中显示
张三的工资,但是我这个代码显示的结果始终是最后一个员工的薪水,请问如何修改??
begin
Edit1.Text:=FieldByName('salary').asstring;
Next;
end;
Edit1文本框中显示的当然是最后工资
在Edit1文本框的OnEnter事件中,
with Qry_Employee do
begin
Close;
SQL.Clear;
SQL.Add('select Salary from T_Employee');
SQL.Add('Where name='''+combobox1.text+'''');
Open;
Edit1.text:=FloatToString(Fieldvalues['Salary']);
end;
with Qry_Employee,ComboBox1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Employee');
Open;
Locate('name',combobox1.Items[combobox1.itemindex],[]);//定位到你选择的记录上
Edit1.Text:=FieldByName('salary').asstring;
end;
begin
Close;
SQL.Clear;
SQL.Add('select coin from T_EnrolType where type='''+Combo_Type.Text+'''');
Open;
Edit_Money.Text:=FloatToStr(Fieldvalues['Coin']);
end;
这样问题解决了。谢谢,看来我的SQL太菜了,
with Qry_Employee,ComboBox1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Employee where name="'
+combobox1.Items[combobox1.itemindex].text+'"');//获得这个人的记录
Edit1.Text:=FieldByName('salary').asstring;
end;