用 if判断一下啊 if RadioButton1.chexked then select from table1 if RadioButton2.chexked then select from table2 if RadioButton3.chexked then select from table3 if RadioButton4.chexked then select from table4
建议搂主用RadioGroup控件,更好,不知道合不合你意
建议用RadioGroupbox;const TableNames: array[0..3] of string=(TableName1, TableName2, TableName3, Tablename4); var TableName, QueryStr: string; begin QueryStr := 'select * from ' + RadioGroupBox.Itemindex.Caption + ' where ' + Edit1.text; //用adoquery查询。end;
function getSql():string;procedure TForm1.Button1Click(Sender: TObject); begin adodataset1.Close; adodataset1.CommandText:=getSql(); adodataset1.Open; end;function TForm1.getSql: string; var str:string; begin if RadioButton1.Checked=true then str:='select * from table1'; if RadioButton2.Checked=true then str:='select * from table2'; if RadioButton3.Checked=true then str:='select * from table3'; if RadioButton4.Checked=true then str:='select * from table4'; result:=str; end;
adoquery1.close; adoquery1.sql.text:='select * from '+#39+radiogroup.itemindex.caption+#39+' where fieldname='+#39+edit1.text+#39; adoquery1.open;
hongqi162(失踪的月亮)兄的比较好,就用他的了!
up 用RadioGroup1; Function GetSql: String; var S:String; begin case RadioGroup1.ItemIndex of 0: S:='select * from table1'; 1: S:='select * from table2'; 2: S:='select * from table3'; 3: S:='select * from table4'; end; Result:=S; end;
的checked
然后写语句
那要写四个.
有什么简体一点的方法
if RadioButton1.chexked then select from table1
if RadioButton2.chexked then select from table2
if RadioButton3.chexked then select from table3
if RadioButton4.chexked then select from table4
TableNames: array[0..3] of string=(TableName1, TableName2, TableName3, Tablename4);
var
TableName, QueryStr: string;
begin
QueryStr := 'select * from ' + RadioGroupBox.Itemindex.Caption + ' where ' + Edit1.text;
//用adoquery查询。end;
begin
adodataset1.Close;
adodataset1.CommandText:=getSql();
adodataset1.Open;
end;function TForm1.getSql: string;
var str:string;
begin
if RadioButton1.Checked=true then str:='select * from table1';
if RadioButton2.Checked=true then str:='select * from table2';
if RadioButton3.Checked=true then str:='select * from table3';
if RadioButton4.Checked=true then str:='select * from table4';
result:=str;
end;
adoquery1.sql.text:='select * from '+#39+radiogroup.itemindex.caption+#39+' where fieldname='+#39+edit1.text+#39;
adoquery1.open;
Function GetSql: String;
var
S:String;
begin
case RadioGroup1.ItemIndex of
0: S:='select * from table1';
1: S:='select * from table2';
2: S:='select * from table3';
3: S:='select * from table4';
end;
Result:=S;
end;