//连接数据库
OnInitADOConn();
//设置查询字符串
_bstr_t bstrSQL = "select * from employees order by 编号 desc";
//_bstr_t bstrSQL = "select * from All order by 编号 desc";
//创建记录集指针对象实例
m_pRecordset.CreateInstance(__uuidof(Recordset));
//打开记录集
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
m_Grid.InsertItem(0,"");
m_Grid.SetItemText(0,0,(char*)(_bstr_t)m_pRecordset->GetCollect("编号"));
m_Grid.SetItemText(0,1,(char*)(_bstr_t)m_pRecordset->GetCollect("姓名"));
m_Grid.SetItemText(0,2,(char*)(_bstr_t)m_pRecordset->GetCollect("性别"));
m_Grid.SetItemText(0,3,(char*)(_bstr_t)m_pRecordset->GetCollect("年龄"));
//将记录集指针移动到下一条记录
m_pRecordset->MoveNext();
}
//断开数据库连接
ExitConnect();
以上代码是将数据库的数据初始化在窗口列表中,完全没问题
但当我把
//设置查询字符串
_bstr_t bstrSQL = "select * from employees order by 编号 desc";
改成_bstr_t bstrSQL = "select * from All order by 编号 desc";
就会出现Runtime error!!!错误我的理解是employees是表的名字,所以我把调用的这个表名改为All,结果出错了。请教大家为什么了!
我测试发现
程序运行到
//打开记录集
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
就会出现,停止运行
OnInitADOConn();
//设置查询字符串
_bstr_t bstrSQL = "select * from employees order by 编号 desc";
//_bstr_t bstrSQL = "select * from All order by 编号 desc";
//创建记录集指针对象实例
m_pRecordset.CreateInstance(__uuidof(Recordset));
//打开记录集
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
m_Grid.InsertItem(0,"");
m_Grid.SetItemText(0,0,(char*)(_bstr_t)m_pRecordset->GetCollect("编号"));
m_Grid.SetItemText(0,1,(char*)(_bstr_t)m_pRecordset->GetCollect("姓名"));
m_Grid.SetItemText(0,2,(char*)(_bstr_t)m_pRecordset->GetCollect("性别"));
m_Grid.SetItemText(0,3,(char*)(_bstr_t)m_pRecordset->GetCollect("年龄"));
//将记录集指针移动到下一条记录
m_pRecordset->MoveNext();
}
//断开数据库连接
ExitConnect();
以上代码是将数据库的数据初始化在窗口列表中,完全没问题
但当我把
//设置查询字符串
_bstr_t bstrSQL = "select * from employees order by 编号 desc";
改成_bstr_t bstrSQL = "select * from All order by 编号 desc";
就会出现Runtime error!!!错误我的理解是employees是表的名字,所以我把调用的这个表名改为All,结果出错了。请教大家为什么了!
我测试发现
程序运行到
//打开记录集
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
就会出现,停止运行
解决方案 »
- C++网络编程HTTP传输结构体
- FTP the application has request a runtime to terminate it in anusual way
- 已知一个IShellFolder 如何用它export出它的IShellFolder2?
- 没可用分啦!哪位老大可怜可怜啊!!!vcforever,获奖了,也得给大家一点口水啊。。。。。。
- help me!
- 有谁知道CSTATIC控件加上NOTIFY属性后,Create中dwStyle如何写?
- 我想去读中科院的MCE工程硕士,有没有人知道这个MCE好不好。
- 有段代码请解释下,
- 用ATL做控件,怎么得到控件容器的RECT?
- 大家来论论Clipboard的用途
- sql server 2005 不能同时执行建库和建表
- ListCtrl被另外的窗口覆盖后变灰界面刷新不正确问题
表名可不是随便能改的。
有主键的,但我在想没主键可以吗?或者主键不是编号,而是“姓名”之类的行不?