我用两个组合框,在第一个里面显示了一个列的查询记录集合。现在想每选择一个数据,第二个组合框里面把在第一个选择的数据作为条件,查询的记录显示在第二个组合框里面,有我编的代码如下:
在初始化里面。。
CString str;
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet->Open(CRecordset::forwardOnly,"select 列1 from 表1");
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列1",str);
组合框1.AddString(str);
m_pSet->MoveNext();
}
m_pSet->Close();
............
CMyview::OnSelEndOkCombo1()
{
CString str,strSQL;
组合框1.GetLbText(组合框.GetCurSel(),str);
strSQL.Format("select 列2 from 表1 where 列1=%s",str);
m_pSet->Open(CRecordset::forwardOnly,strSQL);
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列2",str);
组合框2.AddString(str);
m_pSet->MoveNext();
}
m_pSet->Close();
}
我编译的时候没有问题,可是一执行,出现窗口,我再选择组合框1,马上跳出一个对话框“参数不足,却省为1”,不知道哪里出了问题,大家给我看看,帮帮忙!!!
在初始化里面。。
CString str;
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet->Open(CRecordset::forwardOnly,"select 列1 from 表1");
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列1",str);
组合框1.AddString(str);
m_pSet->MoveNext();
}
m_pSet->Close();
............
CMyview::OnSelEndOkCombo1()
{
CString str,strSQL;
组合框1.GetLbText(组合框.GetCurSel(),str);
strSQL.Format("select 列2 from 表1 where 列1=%s",str);
m_pSet->Open(CRecordset::forwardOnly,strSQL);
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列2",str);
组合框2.AddString(str);
m_pSet->MoveNext();
}
m_pSet->Close();
}
我编译的时候没有问题,可是一执行,出现窗口,我再选择组合框1,马上跳出一个对话框“参数不足,却省为1”,不知道哪里出了问题,大家给我看看,帮帮忙!!!
strSQL.Format("select 列2 from 表1 where 列1=%s",str);
因改为
strSQL.Format("select 列2 from 表1 where 列1='%s'",str);check it please
m_ServerList.GetLbText(m_ServerList.GetCurSel(),str);
出新错误,说‘GetLbText':is not a member of 'combobox';
郁闷!!!
把m_ServerList 的变量类型改为CString在编译:
CString str;
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet->Open(CRecordset::forwardOnly,"select 列1 from 表1");
while(!m_pSet->IsEOF())
{
m_pSet->GetFieldValue("列1",str);
组合框1.AddString(str);
m_pSet->MoveNext();
}
m_pSet->Close();
时出现错误,看来鱼和熊掌不可兼得呀!!!