我的对话框里有两个CCombBox控件,对应的变量分别为m_dept,m_class.
我想实现的功能如下,根据用户的选择,得到m_dept的值,然后用它作为参数查询数据库
得到一个记录集,然后将记录集里面的数据插入到m_class里面去。
我在第一个控件的下拉消息中添加代码,有错吗?
好想没触发该消息。并且提示文档的ASSERT_VIALD出现错误。
void CStuInfoBrowse::OnDropdownComboDept()
{
// TODO: Add your control notification handler code here
ADOConn adoconn;
int count,index;
CString dept,sql;
UpdateData(1);
count=m_dept.GetCount();
index=m_dept.GetCurSel(); //得到当前用户的选择
m_dept.GetLBText(index,dept);//获得其内容
if(dept=="计算机科学与技术")
param="85";
else if(dept=="教育技术系")
param="83";
sql.Format("SELECT DISTINCT LEFT(学号, 5) AS 班级 FROM 学生信息表 WHERE (LEFT(学号,2)='%s') GROUP BY 学号",param); //?SQL语句应该不会有错吧?
adoconn.GetRecordSet(_bstr_t(sql));
long rdcount=adoconn.m_pRecordset->GetRecordCount();
if(rdcount<=0)
AfxMessageBox("记录集为空或数目不可确定!");
else
{ if(adoconn.m_pRecordset->adoBOF) adoconn.m_pRecordset->MoveFirst();
while(!adoconn.m_pRecordset->adoEOF)
{ _variant_t vIndex;
vIndex=long(0);
_variant_t vclass;
CString classparam;
vclass=adoconn.m_pRecordset->GetCollect(vIndex);
classparam=vclass.bstrVal;
classparam.TrimRight();
int rtn=m_class.AddString(LPCTSTR(classparam));
if(rtn==CB_ERR||rtn==CB_ERRSPACE)
{
AfxMessageBox("插入错误或空间不够!");
}
adoconn.m_pRecordset->MoveNext();
}
}
UpdateData(0);
}
我想实现的功能如下,根据用户的选择,得到m_dept的值,然后用它作为参数查询数据库
得到一个记录集,然后将记录集里面的数据插入到m_class里面去。
我在第一个控件的下拉消息中添加代码,有错吗?
好想没触发该消息。并且提示文档的ASSERT_VIALD出现错误。
void CStuInfoBrowse::OnDropdownComboDept()
{
// TODO: Add your control notification handler code here
ADOConn adoconn;
int count,index;
CString dept,sql;
UpdateData(1);
count=m_dept.GetCount();
index=m_dept.GetCurSel(); //得到当前用户的选择
m_dept.GetLBText(index,dept);//获得其内容
if(dept=="计算机科学与技术")
param="85";
else if(dept=="教育技术系")
param="83";
sql.Format("SELECT DISTINCT LEFT(学号, 5) AS 班级 FROM 学生信息表 WHERE (LEFT(学号,2)='%s') GROUP BY 学号",param); //?SQL语句应该不会有错吧?
adoconn.GetRecordSet(_bstr_t(sql));
long rdcount=adoconn.m_pRecordset->GetRecordCount();
if(rdcount<=0)
AfxMessageBox("记录集为空或数目不可确定!");
else
{ if(adoconn.m_pRecordset->adoBOF) adoconn.m_pRecordset->MoveFirst();
while(!adoconn.m_pRecordset->adoEOF)
{ _variant_t vIndex;
vIndex=long(0);
_variant_t vclass;
CString classparam;
vclass=adoconn.m_pRecordset->GetCollect(vIndex);
classparam=vclass.bstrVal;
classparam.TrimRight();
int rtn=m_class.AddString(LPCTSTR(classparam));
if(rtn==CB_ERR||rtn==CB_ERRSPACE)
{
AfxMessageBox("插入错误或空间不够!");
}
adoconn.m_pRecordset->MoveNext();
}
}
UpdateData(0);
}
解决方案 »
- 求助usb hid数据,大牛帮忙看看
- 把.c文件改成.cpp就出错,为什会找不到函数呢?
- MFC入门,请大家给点建议
- VS2005生成的程序,在某些机器上运行出错.Create process failed code 14001
- 关于InvalidateRect()和OnPaint()的疑问?
- 帮帮我吧,我郁闷了一天了,都进来看看吧.求你们了.
- 如何自画一个类似VC中Flat样式的按钮?
- 这个网站里的东西真全啊!!
- 弱智问题:在MFC中,自定义的两个类需要互相传值怎么办?
- 请问LPCTSTR,LPCSTR,LPTSTR,LPSTR等字符串有什么区别吗?
- 如何修改路径选择对话框
- 如何才能像QQ面板那样啊
注明原帖的url,发送完之后请发消息通知我。希望可以帮到你。