我用mfc+odbc+access做了一个程序,可是我运行时提示 "在调用SQLFetchScroll/SQLExtendFetch之前,没有列被绑定",我的数据库名字是"addresslist",想打开的数据表的名字是"person", 我没有为person建立Crecordset类,具体程序如下,请各位帮帮讲解一下,,谢谢了!
//确定列名 m_ctrlperson为ClistCtl的变量
m_ctrlperson.InsertColumn(0,"序号");
m_ctrlperson.InsertColumn(1,"姓名");
m_ctrlperson.InsertColumn(2,"性别");
m_ctrlperson.InsertColumn(3,"所在学校");
m_ctrlperson.InsertColumn(4,"联系电话");
m_ctrlperson.InsertColumn(5,"手机号码");
m_ctrlperson.InsertColumn(6,"家庭住址");
m_ctrlperson.InsertColumn(7,"工作单位");
m_ctrlperson.InsertColumn(8,"E_mail地址");
m_ctrlperson.InsertColumn(9,"OICQ号码");
//重新分配列宽
m_ctrlperson.SetColumnWidth(0,40);
m_ctrlperson.SetColumnWidth(1,60);
m_ctrlperson.SetColumnWidth(2,40);
m_ctrlperson.SetColumnWidth(3,80);
m_ctrlperson.SetColumnWidth(4,100);
m_ctrlperson.SetColumnWidth(5,100);
m_ctrlperson.SetColumnWidth(6,150);
m_ctrlperson.SetColumnWidth(7,150);
m_ctrlperson.SetColumnWidth(8,150);
m_ctrlperson.SetColumnWidth(9,80);
//扩展风格
m_ctrlperson.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES);//|LVS_SHOWSELALWAYS);
//查找记录并按ID升序排列
m_query.Format("select * from person order by ID ASC");
//首先确保数据库打开
if(!m_database.IsOpen())
{
m_database.Open(_T("addresslist"));
// m_database.Open(_T("person"));
}
//对列表控件的内容更新,清空原来的内容
m_ctrlperson.DeleteAllItems();
//创建记录集
CRecordset m_personset(&m_database);
m_personset.Open(AFX_DB_USE_DEFAULT_TYPE,m_query);
CDBVariant varValue;
char buf[20];
//用来记录当前记录的序号
int i=0;
//如果表中有记录,打开后将游标定在第一位,使记录集中的第一条记录成为当前记录
if(m_personset.GetRecordCount()!=0) m_personset.MoveFirst();
while(!m_personset.IsEOF())
{
int temp=0;
//对整型数字的处理
m_personset.GetFieldValue(temp,varValue);
sprintf(buf,"%d",varValue.m_lVal);m_ctrlperson.InsertItem(i,buf);
//对字符串显示处理
m_personset.GetFieldValue(1,varValue);
m_ctrlperson.SetItemText(i,1,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(2,varValue);
m_ctrlperson.SetItemText(i,2,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(3,varValue);
m_ctrlperson.SetItemText(i,3,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(4,varValue);
m_ctrlperson.SetItemText(i,4,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(5,varValue);
m_ctrlperson.SetItemText(i,5,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(6,varValue);
m_ctrlperson.SetItemText(i,6,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(7,varValue);
m_ctrlperson.SetItemText(i,7,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(8,varValue);
m_ctrlperson.SetItemText(i,8,varValue.m_pstring->GetBuffer(1));
m_personset.GetFieldValue(9,varValue);
m_ctrlperson.SetItemText(i,9,varValue.m_pstring->GetBuffer(1));
m_personset.MoveNext();
i++;
}