如何用Option1,Option2来选择查询
选择好Option1,Option2.然后Command1_Click按钮来查询,
用什么方法好,用Select Case Index Case [值]怎么来做.或是别的方法
==========================
选择Option1,查询如下
sql "SELECT * from temp1 WHERE id= ' " & Text1.Text & " ' "
rs.Open sql, cn,1,3
If Not rs.EOF Then
DataGrid1.Columns(0).DataField= "id "
DataGrid1.Columns(1).DataField= "name "
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End If
Set rs = Nothing
End Sub
选择Option2,查询如下
sql "SELECT * from temp2 WHERE add= ' " & Text1.Text & " ' "
rs.Open sql, cn,1,3
If Not rs.EOF Then
DataGrid1.Columns(0).DataField= "add "
DataGrid1.Columns(1).DataField= "PF "
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End If
Set rs = Nothing
End Sub
[解决办法]
直接用select Case Index没法做,
可实现的方法大概有
1.用一个变量表示那个option被选中了
例如
private opselected as integer
sub option1_Click()
opselected=1
end sub
sub option2_click()
opselected=2
end sub
sub command_click()
select case opselected
case 1
.......
case 2
..........
end select
end sub
2.用if else .......来判断
if option1.value then
.......
elseif option2.value then
..........
end if