CDATAGRID 控件 数据不显示
大家帮忙
我采用的是vs2002,在使用cdatagrid绑定数据时,数据查出来了,但是datagrid就是不显示
CString sql="";
CDBAccess oDB(); //构造函数带有打开连接功能 ,析构函数关闭连接
sql.Format("%s WHERE SCR='%s' and SQDBM='' order by id",CCADPrintDetail_SELECT,lpcRyid);
//_RecordsetPtr rec=oDB.ExecSql(sql);
//if(rec==NULL)
//{
// obj.SetRefDataSource(NULL);
//}
//else
//{
///* int i=0;
// while(!rec->adoEOF)
// {
// i++;
// rec->MoveNext();
// }*/
// obj.SetRefDataSource(rec);
// obj.SetCaption("你好");
// obj.Refresh();
// //rec->Close();
//}
_RecordsetPtr pRecordset;
// TRACE("SQL语句: %s\r\n", lpcSql);
try
{
//OpenConn();
pRecordset.CreateInstance("ADODB.Recordset");
pRecordset-> CursorType = adOpenStatic;
pRecordset->CursorLocation=adUseClient;
pRecordset->Open((_variant_t)sql.AllocSysString(), _variant_t((IDispatch *)oDB.m_pConnection, true),
adOpenStatic, adLockOptimistic, adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format(_T("SQL语句执行失败!\r\n错误信息:%s"), e.ErrorMessage());
//AfxMessageBox(errormessage);
//CNote::WriteNote(errormessage);
MessageBox(NULL,errormessage,_T("数据库信息"),MB_OK);
pRecordset = NULL;
}
if(pRecordset==NULL)
{
obj.SetRefDataSource(NULL);
}
else
{
/* int i=0;
while(!rec->adoEOF)
{
i++;
rec->MoveNext();
}*/
obj.SetRefDataSource(pRecordset);
obj.SetCaption("你好");
obj.Refresh();
//rec->Close();
}