vb 数据库记录的查询

我在Oncomm 事件里面显示了一个表,这个表里面有个“报警状态”的字段,状态有这么几种,正常,报警,故障,现在呢我想把这个表里面的报警和故障的个数统计出来,报警个数放在text1,故障个数放在text2,我在Oncomm里面是这样做的,
Adodc10.CommandType = adCmdText
Adodc10.RecordSource = "select * from 实时显示表 order by 地址编号 asc"
Adodc10.Refresh
Set DataGrid2.DataSource = Adodc10

Adodc9.CommandType = adCmdText '报警点数
Adodc9.RecordSource = "select * from 实时显示表 where 报警状态='报警'"
Adodc9.Refresh
Text1.Text = CStr(Adodc9.Recordset.RecordCount)
Adodc8.CommandType = adCmdText '故障点数
Adodc8.RecordSource = "select * from 实时显示表 where 报警状态='故障'"
Adodc8.Refresh
Text2.Text = CStr(Adodc8.Recordset.RecordCount)
感觉很麻烦,想请高手指点一下,有没有更简单方法

第1个回答  2013-10-11
select (select * from 实时显示表 where 报警状态='报警') as 报警点数,(select * from 实时显示表 where 报警状态='故障') as 故障点数 FROM 实际显示表 WHERE 这里如果有条件再添加

text1.text=Recordset.Fields(0).Value & ""
text2.text=Recordset.Fields(1).Value & ""