void CJcsjDlg::OnQry1() 
{
// TODO: Add your control notification handler code here
UpdateData(true);
CString combo;
int a=m_qrymsg.GetCurSel();
if(a!=-1)
m_qrymsg.GetLBText(a,combo);
else
combo="";
if(combo==""||m_msg=="")
{
AfxMessageBox("必须选择项目并输入查询信息");
return;
} CoInitialize(NULL);
_ConnectionPtr pconnect(__uuidof(Connection));
_CommandPtr comd(__uuidof(Command));
_RecordsetPtr record(__uuidof(Recordset));
pconnect->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=syjl";
pconnect->Open("","","",NULL);
comd->put_ActiveConnection(_variant_t((IDispatch *)pconnect));
CString cmd;
CString cmd1;//保存select count(*)获取记录数目
//标准SQL语句
if(combo=="IP地址")
{
cmd="select * from jcsj where IPADDR='";
cmd1="select count(*) from jcsj where IPADDR='";
}
if(combo=="责任人")
{
cmd="select * from jcsj where ZRR='";
cmd1="select count(*) from jcsj where ZRR='";
}
cmd+=m_msg;cmd1+=m_msg;
cmd+="'";
cmd1+="'";
comd->CommandText=_bstr_t(cmd1);//得到SQL语句,求解记录数目
record=comd->Execute(NULL,NULL,adCmdText);
//得到记录的总数目,在vCount.lVal中保存
variant_t vCount = record->GetCollect((_variant_t)((long)0));
if(vCount.lVal==0)
{
AfxMessageBox("查无记录");
return;
}
//执行查询语句
comd->CommandText=_bstr_t(cmd);//得到SQL语句
record=comd->Execute(NULL,NULL,adCmdText);
if(num+1>=vCount.lVal||vCount.lVal==0)
GetDlgItem(IDC_NEXT)->EnableWindow(false);
else
GetDlgItem(IDC_NEXT)->EnableWindow(true);
if(num<1)
GetDlgItem(IDC_LAST)->EnableWindow(false);
else
GetDlgItem(IDC_LAST)->EnableWindow(true);
if(!record->end)
{
record->MoveFirst();
//从头开始定位到num位置,因此可以实现查看“前一条”和“后一条”功能
record->Move(num);
//出现runtime error
                  m_id=(char*)(_bstr_t)record->GetCollect("IPADDR");
m_name=(char*)(_bstr_t)record->GetCollect("ZRR");
UpdateData(false);
}
if(record->State)
record->Close();
if(pconnect->State)
pconnect->Close();
comd.Release();
record.Release();
pconnect.Release();
CoUninitialize(); GetDlgItem(IDC_QRY3)->EnableWindow(false);
GetDlgItem(IDC_COMBO2)->EnableWindow(false);
GetDlgItem(IDC_MSG)->EnableWindow(false);
GetDlgItem(IDC_AGAIN)->EnableWindow(true);
GetDlgItem(IDC_DEL)->EnableWindow(true);
}