我在VC++6.0写了个数据库程序。我在网上搜了,都不行。
sql = "Select * from Mytable";
Mytable里有许多的数据,(不过有些字段没有写数据).
bool ADOConn::MoveFirst ()
{
int ncount = this->m_pRecordset->GetRecordCount();
try
{
// 这个if怎么写都不行啊
if(!this->m_pRecordset->adoEOF||!this->m_pRecordset->adoBOF)
this->m_pRecordset->MoveFirst ();
}
catch (_com_error e)
{
AfxMessageBox (e.Description () ); return false;
} return true;
}
为什么总是说“OF和BOF有一个为真“的错误啊?我怎么处理数据库里面的空数据呢?因为我要把数据写到ListControl里面。
我找一个上午了,谢谢了各位,我一定给分。(就是数据库里为空,怎么处理啊)
sql = "Select * from Mytable";
Mytable里有许多的数据,(不过有些字段没有写数据).
bool ADOConn::MoveFirst ()
{
int ncount = this->m_pRecordset->GetRecordCount();
try
{
// 这个if怎么写都不行啊
if(!this->m_pRecordset->adoEOF||!this->m_pRecordset->adoBOF)
this->m_pRecordset->MoveFirst ();
}
catch (_com_error e)
{
AfxMessageBox (e.Description () ); return false;
} return true;
}
为什么总是说“OF和BOF有一个为真“的错误啊?我怎么处理数据库里面的空数据呢?因为我要把数据写到ListControl里面。
我找一个上午了,谢谢了各位,我一定给分。(就是数据库里为空,怎么处理啊)
那 ncount 怎么老是返回为-1啊?明明是有许多的数据的啊。
m_pRecordset->Open (bstrSQL, this->m_pConnection.GetInterfacePtr(), adOpenDynamic,
adLockOptimistic, adCmdText);
只留下eof或者bof
“去掉一半呢
只留下eof或者bof”
这个我也试过了,只是我的数据里有些脏数据(就是在某些字段里,没有数据)。我该怎么办?
在where里面过滤呢?
或者取出来判断GetCollect("字段名").vt==VT_NULL
我试了也不行,
to 我是菜鸟
我的 m_pRecordset- >GetRecordCount(),就为-1啊。没有用GetCollect()。
{
try
{
// connect database, IF Connection is NULL, THEN Resume
if( m_pConnection == NULL)
this->OnInitDBConnect(); // Create Recordset Object
m_pRecordset.CreateInstance (__uuidof(Recordset)); m_pRecordset->CursorLocation = adUseClient;
// Get Record in TABLE
m_pRecordset->Open (bstrSQL, m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic, adCmdText); }
// catch UNNormal
catch( _com_error e)
{
// Display error INFORMATION
AfxMessageBox (e.Description());
}
int count = this->m_pRecordset->GetRecordCount();//在这个地方,得到0值啊。
// Return Recordset
return this->m_pRecordset;}
各位,是我错了。
对不起了。我用的是EXCEL文件,我没有选择所有的数据,所以有不存在的数据。
我每个人都给分,除我自己外。谢谢各位了。