[求助] 帮忙看下我的代码能实现不?编译无错误 运行 程序崩溃

qq4671019471 2012-05-21 08:36:01
CDatabase m_database;

m_database.Open(NULL,FALSE,FALSE,_T("ODBC;Dsn=student;server=localhost;uid=;pwd=")); //打开数据源
DWORD dwExStyle = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE;
m_ListTeacher.ModifyStyle(0,LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS);
m_ListTeacher.SetExtendedStyle(dwExStyle);
m_ListTeacher.InsertColumn(0,"职工号",LVCFMT_CENTER,50,0);
m_ListTeacher.InsertColumn(1,"姓名",LVCFMT_CENTER,50,0);
m_ListTeacher.InsertColumn(2,"部门",LVCFMT_CENTER,50,0);
CString strSQL;
strSQL.Format("select * from user_pass");
//ListAll(strSQL); //打开教职工表,将所有记录显示在列表中

//return TRUE; // return TRUE unless you set the focus to a control
if (m_pSet->IsBOF())
{ // detects empty recordset

return;

}

int i=0;
do
{
m_pSet->MoveFirst();

while(!m_pSet->IsEOF())
{

m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
m_pSet->MoveNext(); //移到下一条记录
i++;
}
}while(i==100);
...全文
137 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq4671019471 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
m_pSet->MoveNext(); //移到下一条记录
m_pSet是个什么东西啊?_R……
[/Quote]m_pSet->m_username,m_pSet->m_password,m_pSet->m_ID
我把数据库里的 username password id在程序中添加的赋值
能告诉我你QQ不?我真想请教你帮我解决下
qq4671019471 2012-05-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
这么写不对吗?
另外楼主在数据库操作的时候加上try...catch看下错误是什么
[/Quote]源代码是tyl 加catch 但是编译时 catch 语句中有错误
这是经过我多次修改后的代码 导致程序崩溃的语句就是do
{
m_pSet->MoveFirst();

while(!m_pSet->IsEOF())
{

m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
m_pSet->MoveNext(); //移到下一条记录
i++;
}
}while(i==100);
上面的
lxsun79 2012-05-24
  • 打赏
  • 举报
回复
m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
m_pSet->MoveNext(); //移到下一条记录
m_pSet是个什么东西啊?_Recordset指针?m_pSet->m_username,m_pSet->m_password,m_pSet->m_ID
这又和_Recordset指针又什么关系?
daxx1986556 2012-05-23
  • 打赏
  • 举报
回复
m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
这么写不对吗?
另外楼主在数据库操作的时候加上try...catch看下错误是什么
qq4671019471 2012-05-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

这里不对

m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
--》
m_ListTeacher.InsertIt……
[/Quote]这样改了程序还是崩溃 我不会调试 怎么办啊
qq4671019471 2012-05-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

调试看看那条语句崩溃的?m_pSet哪儿来的?是有效值吗?
[/Quote]m_pSet 是由CDataSet * 类型的
qq4671019471 2012-05-21
  • 打赏
  • 举报
回复
谢了我先试试看 不行再解决
  • 打赏
  • 举报
回复
一般是
m_list.InsertColumn( 0, "ID", LVCFMT_LEFT, 40 );//插入列
m_list.InsertColumn( 1, "NAME", LVCFMT_LEFT, 50 );

int nRow = m_list.InsertItem(0, "11");// 插入行
m_list.SetItemText(nRow, 1, "jacky");//设置其它列数据
Eleven 2012-05-21
  • 打赏
  • 举报
回复
程序崩溃的话,你Debug下call stack看下函数调用堆栈,看哪里出错了
Eleven 2012-05-21
  • 打赏
  • 举报
回复
这里不对

m_ListTeacher.InsertItem(i,m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
--》
m_ListTeacher.InsertItem(i,_T(""));
m_ListTeacher.SetItemText(i,0, m_pSet->m_username);
m_ListTeacher.SetItemText(i,1,m_pSet->m_password);
m_ListTeacher.SetItemText(i,2,m_pSet->m_ID);
黑泡泡选手 2012-05-21
  • 打赏
  • 举报
回复
调试看看那条语句崩溃的?m_pSet哪儿来的?是有效值吗?
qq4671019471 2012-05-21
  • 打赏
  • 举报
回复
我是想把数据库里的表的内容 显示在控件list control 中

4,011

社区成员

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

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