救命啊 谁来帮我看看这段代码~

kingcool16 kingcool16 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
谁能帮看看这段代码啊 我想从数据库的表里把数据读出来然后显示在list control控件里 可是不管我咋弄都没反应啊 我无语了
谁知道是怎么回事 帮帮我吧
UpdateData();
HRESULT hRe;
char buf[200],gpjid[20],gorganizer[50];
_variant_t theValue;//操作数据库所必用的类型

try
{

connDB();

memset(buf,0,sizeof(buf));
strcpy(buf,"select pjid from PJ_DATE where state='1'");
hRe=rs->Open(_variant_t(buf),pConn.GetInterfacePtr(),adOpenForwardOnly,adLockReadOnly,adCmdText);
memcpy(gpjid,(const char*)(_bstr_t)(_variant_t)rs->GetCollect("pjid").bstrVal,sizeof(gpjid));
//memcpy(gorganizer,(const char*)(_bstr_t)(_variant_t)rs->GetCollect("organizer").bstrVal,sizeof(gorganizer));
m_listpj.SetItemText(1,1,gpjid);
//m_listStu.SetItemText(2,2,gorganizer);
}
catch(_com_error &e)
{
char buf[200];
memset(buf,0,200);
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
sprintf(buf,"\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
//AddLogInfo(buf);
rs->Close();
pConn->Close();
return ;
}
}

还有就是谁能帮我解释一下这段代码的意思 重点说一下红的地方
m_listClass.DeleteAllItems();

int i;
char classid[3],buf[200],id[3];
char classnumid[13];//班级编号
HRESULT hRe;
_variant_t theValue;
int index=m_comYear.GetCurSel(); if(index==-1)
{
AfxMessageBox("请首先选择专业年级");
return;
}

CString temp,strspeid,strspe;
m_comYear.GetLBText(index,temp);
// int n = temp.Find(':');
// strspeid = temp.Left( n ); // 前面的n个字符
// strspe = temp.Mid( n+1 ); // 从中间第n+1字符到未尾的字符串
int n = temp.Find(':');
strspe = temp.Left( n ); // 前面的n个字符
strspeid = temp.Mid( n+1 ); // 从中间第n+1字符到未尾的字符串 UpdateData( FALSE );


try
{
memset(buf,0,sizeof(buf));
sprintf(buf,"select class_id,class_numid from class where class_speid='%s'",strspeid);
hRe=rs->Open(_variant_t(buf),pConn.GetInterfacePtr(),adOpenForwardOnly,adLockReadOnly,adCmdText);
if(SUCCEEDED(hRe))
{
i=0;
while(!rs->adoEOF)
{
memcpy(classid,(const char*)(_bstr_t)rs->GetCollect("class_numid").bstrVal,sizeof(classid));
memcpy(classnumid,(const char*)(_bstr_t)rs->GetCollect("class_id").bstrVal,sizeof(classnumid));

sprintf(id,"%d",i+1);
m_listClass.InsertItem(i,id);
// m_listClass.InsertItem( LVIF_TEXT|LVIF_STATE, i, id, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,0, 0);
m_listClass.SetItemText(i,1,classnumid);
m_listClass.SetItemText(i,2,strspe);
m_listClass.SetItemText(i,3,classid);

rs->MoveNext();
i++;
}
rs->Close();
}
m_listStu.DeleteAllItems();
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
kingcool16
VC/MFC 16,550 成员 421,606 内容