列表视图显示记录信息
为对话框类 CTeacherMISDlg 添加 Private 成员函数 ListAll(CString strSQL),用于在列表视图中显示所有记录信息
CStudentMISDlg::ListAll(CString strSQL)
{
m_LIST_Student.DeleteAllItems();//清空列表视图
CStudentSetm_Studentset;//定义记录集对象
try
{
if(m_Studentset.IsOpen()) //如果记录集是打开的,关闭之
m_Studentset.Close();
if(
!m_Studentset.Open(CRecordset::snapshot,strSQL))
{ //以 snapshot 的方式打开表,如果不能打开,报错处理
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
}
catch ( CDBException *e ) // 异常捕获
{
e->ReportError();
}
int nIndex=0;//列表视图指向第 1 行
m_Studentset.MoveFirst(); //记录指针指向第 1 条记录
while(!m_Studentset.IsEOF())
{
LV_ITEM lvItem;
lvItem.mask=LVIF_TEXT;
lvItem.iItem=nIndex; //行
lvItem.iSubItem=0;//列
lvItem.pszText="";
m_LIST_Student.InsertItem(&lvItem); //在列表视图中插入一行,每行 10 列
m_LIST_Student.SetItemText(nIndex,0,m_Studentset.m_ID);
m_LIST_Student.SetItemText(nIndex,1,m_Studentset.m_Name );
m_LIST_Student.SetItemText(nIndex,2,m_Studentset.m_Dept);
m_LIST_Student.SetItemText(nIndex,3,m_Studentset.m_Eng);
m_LIST_Student.SetItemText(nIndex,4,m_Studentset.m_Math);
m_LIST_Student.SetItemText(nIndex,5,m_Studentset.m_Ave);
m_Studentset.MoveNext(); //后移记录
nIndex++; //行数加 1
}
m_Studentset.Close();
}
私有这样定义吗 啥类型啊
private:
ListAll(CString strSQL);
错误
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(209) : error C2065: 'CStudentSet' : undeclared identifier
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(209) : error C2146: syntax error : missing ';' before identifier 'm_Studentset'
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(209) : error C2065: 'm_Studentset' : undeclared identifier
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(212) : error C2228: left of '.IsOpen' must have class/struct/union type
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(213) : error C2228: left of '.Close' must have class/struct/union type
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(215) : error C2228: left of '.Open' must have class/struct/union type
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(218) : error C2561: 'ListAll' : function must return a value
c:\users\liang\desktop\新建文件夹\studentmis\studentmisdlg.h(66) : see declaration of 'ListAll'
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(227) : error C2228: left of '.MoveFirst' must have class/struct/union type
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(228) : error C2228: left of '.IsEOF' must have class/struct/union type
C:\Users\LIANG\Desktop\新建文件夹\StudentMIS\StudentMISDlg.cpp(228) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
[解决办法]
#include "studentset.h"
[解决办法]
void CStudentMISDlg::ListAll(CString strSQL)
[解决办法]
你的CStudentSet是哪儿来的
如果是自定义的要包含同文件啊
函数如果不想返回值就用void啊