vc访问数据库时的问题!
我程序中的一个函数如下:void CCourseDlg::OnSelchangeMajorCombo()
{
// TODO: Add your control notification handler code here
CString vMajorName;
int nIndex=m_Major.GetCurSel();
m_Major.GetLBText(nIndex,vMajorName);
if(vMajorName!="")
GetDlgItem(IDC_COURSE_LIST)->EnableWindow(true);
CMajorRecordset *pMajorSet=new CMajorRecordset( &((CSystemApp *)AfxGetApp())->m_db );
if(pMajorSet==NULL)
{
MessageBox( "分配内存错误!", "组卷系统", MB_OK | MB_ICONWARNING );
return;
}
CString vSql="select distinct CourseName from zhuanyeke where MajorName="+vMajorName+"";
pMajorSet->Open(0,vSql,0);
while(!pMajorSet->IsEOF())
{
m_CourseList.AddString(pMajorSet->m_CourseName);
pMajorSet->MoveNext();
}
pMajorSet->Close();
delete pMajorSet;
}
运行后老是提示说列名无效,未能准备语句!
比如当选中了"计算机"时,就说"列名'计算机'无效,未能准备语句!"
这是怎么回事?