调用GetFieldValue()函数时出错,如何解决,请教。进来有分。

xhyxyr 2003-04-09 11:07:50
我的程序段如下:
CRecordset m_set;
CString strSQL;
strSQL="select count(*) from table1";
m_set.Open(CRecordset::forwardOnly,_T(strSQL),CRecordset::readOnly);
CString str;
m_set.GetFieldValue((short)0,str);
int i=atoi(str);();//i为记录总数

但在调用GetFieldValue()函数时出错:错误提示为:Invalid Descriptor Index。为何?!
...全文
303 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
busuy 2003-04-09
  • 打赏
  • 举报
回复
试-试:
int temp=0;
CString str;
m_set.GetFieldValue(temp,str);


piethy 2003-04-09
  • 打赏
  • 举报
回复
改sql后有没有改GetFieldValue的调用方式
casinosun 2003-04-09
  • 打赏
  • 举报
回复
同意
xhyxyr 2003-04-09
  • 打赏
  • 举报
回复
也不行。
zhaolaoxin 2003-04-09
  • 打赏
  • 举报
回复
把strSQL改为:
strSQL = "select count(*) as reccount from table1";
xhyxyr 2003-04-09
  • 打赏
  • 举报
回复
不行。
piethy 2003-04-09
  • 打赏
  • 举报
回复
(short)0
改成short index = 0;
m_set.GetFieldValue(index,str);
试试
我好像也遇到过
maoxianwang 2003-04-09
  • 打赏
  • 举报
回复
跟踪一下recordset

while(!m_set.IsEOF())
m_set.MoveNext();

TRACE(_T("There are %d record\n"),m_set.GetRecoreCount());

看看是不是记录集没有打开
small_wei 2003-04-09
  • 打赏
  • 举报
回复
我的数据库是sql server
m_set.GetFieldValue((short)0,str);//没有错
small_wei 2003-04-09
  • 打赏
  • 举报
回复
我在我这里试了一下,没有问题。程序是用你的。你跟踪一下,可能不是这里的问题。
LuckFox 2003-04-09
  • 打赏
  • 举报
回复
CRecordset m_set;
CString strSQL;
strSQL = "select count(*) as reccount from table1";
m_set.Open(CRecordset::forwardOnly,_T(strSQL),CRecordset::readOnly);
CString str;
m_set.GetFieldValue("reccount",str);
int i=atoi(str);//i为记录总数
void CMainDlg::OnAdd() { // TODO: Add your control notification handler code here //本对话框对应的数据库连接关闭 m_database.Close(); //新建一个CAddInfoDlg的对象 CAddInfoDlg dlg; //新对话框建立到数据库连接 dlg.m_database.Open(_T("addresslist")); //弹出新对话框 dlg.DoModal(); //新对话框关闭后,在原对话框中刷新数据显示 RefreshData(); } void CMainDlg::OnEdit() { // TODO: Add your control notification handler code here m_database.Close();//本对话框断开与数据库的连接 CModifyDlg dlg; dlg.m_database.Open(_T("addresslist"));//打开数据库 int i=m_ctrlperson.GetSelectionMark(); CString strSQL; int id=atoi(m_ctrlperson.GetItemText(i,0)); CPersonSet m_recordset; CDBVariant varValue; if(i==-1) { MessageBox("请选择一条要修改的记录!","提示",MB_OK|MB_ICONINFORMATION); } else { int temp=0; strSQL.Format("select * from person where ID=%d",id); m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL); m_recordset.GetFieldValue(temp,varValue); dlg.m_modid=varValue.m_lVal; m_recordset.GetFieldValue(1,varValue); dlg.m_modname=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(2,varValue); dlg.m_modsex=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(3,varValue); dlg.m_modrelation=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(4,varValue); dlg.m_modtelephone=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(5,varValue); dlg.m_modhandphone=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(6,varValue); dlg.m_modaddress=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(7,varValue); dlg.m_modworkplace=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(8,varValue); dlg.m_modemail=varValue.m_pstring->GetBuffer(1); m_recordset.GetFieldValue(9,varValue); dlg.m_modoicq=varValue.m_pstring->GetBuffer(1); //m_database.Close();//此处不能断开与数据库的连接 dlg.DoModal(); RefreshData(); } }

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧