代码如下
_ConnectionPtr pMyConnect(__uuidof(Connection));
_RecordsetPtr m_pRecordset(__uuidof(Recordset)); // pMyConnect->ConnectionString = "Provider = SQLOLEDB; Server = .; Database = testDB; uid = sa; pwd = sa;"; CString strConnect="Provider = SQLOLEDB; Data Source = .; Initial Catalog = testDB; uid = sa; pwd = sa;";
CString strSel = "select * from tblPerson";
_variant_t varSel(strSel);
_variant_t varConn(strConnect);
_bstr_t bstrConn(strConnect); try
{
pMyConnect->Open(bstrConn,"sa","sa",NULL);
}
catch (_com_error &e)
{
::MessageBox(NULL, e.Description(), "警告",MB_OK|MB_ICONWARNING);
}
try
{
m_pRecordset->Open(varSel, varConn, adOpenKeyset, adLockOptimistic, adCmdTable);
}
catch (_com_error &e)
{
::MessageBox(NULL, "无法打开tlbPerson表。","提示", MB_OK|MB_ICONWARNING);
}问题出在这个地方
m_pRecordset->Open大家给看一下..谢谢了
_ConnectionPtr pMyConnect(__uuidof(Connection));
_RecordsetPtr m_pRecordset(__uuidof(Recordset)); // pMyConnect->ConnectionString = "Provider = SQLOLEDB; Server = .; Database = testDB; uid = sa; pwd = sa;"; CString strConnect="Provider = SQLOLEDB; Data Source = .; Initial Catalog = testDB; uid = sa; pwd = sa;";
CString strSel = "select * from tblPerson";
_variant_t varSel(strSel);
_variant_t varConn(strConnect);
_bstr_t bstrConn(strConnect); try
{
pMyConnect->Open(bstrConn,"sa","sa",NULL);
}
catch (_com_error &e)
{
::MessageBox(NULL, e.Description(), "警告",MB_OK|MB_ICONWARNING);
}
try
{
m_pRecordset->Open(varSel, varConn, adOpenKeyset, adLockOptimistic, adCmdTable);
}
catch (_com_error &e)
{
::MessageBox(NULL, "无法打开tlbPerson表。","提示", MB_OK|MB_ICONWARNING);
}问题出在这个地方
m_pRecordset->Open大家给看一下..谢谢了
解决方案 »
- 如何通过全局鼠标钩子获取其他窗口选中文本内容
- 老调重弹 订票系统 不要WEB版本 VC+SQL Server如何 请进来帮我解惑
- 如何给已发的贴子追加分数?
- 图象处理当中的一个调试的问题
- CFormView中的变量如何传递给新建立的模式对话框中的变量。
- 请教一个问题
- _bstr_t 这个类是起什么作用的
- 各位大哥,系统空闲时发送什么消息?在线等待!
- 超难问题,大家发表一下意见,来者有分!(关于ldap的)
- mfc窗口上的控件布局问题,工具条上的布局按钮有的不能用
- 发送程序60多个线程的时候不丢包,增为300多个线程,就偶尔丢包,是什么原因呢?
- 0x7c80a34e 处未处理的异常: 0xC0000005: 读取位置 0x016c3000 时发生访问冲突
{
m_pRecordset->Open(varSel, varConn, adOpenKeyset, adLockOptimistic, adCmdTable);
}
catch (_com_error &e)
{
e->ErrorMessage(); //看看是什么?
::MessageBox(NULL, "无法打开tlbPerson表。","提示", MB_OK|MB_ICONWARNING);
}
是
IDispatch error #3149.这个是不是代表第二个参数有问题啊?
recordset.Open Source, ActiveConnection, CursorType, LockType, Options参数说明:
Source 可选,变体型,计算 Command 对象的变量名、SQL 语句、表名、存储过程调用或持久 Recordset 文件名。 ActiveConnection 可选。变体型,计算有效 Connection 对象变量名;或字符串,包含 ConnectionString 参数。
CursorType 可选,CursorTypeEnum 值,确定提供者打开 Recordset 时应该使用的游标类型。
可为下列常量之一(参阅 CursorType 属性可获得这些设置的定义)。
值 常量 说明
--- ------------------- -----------------------
0 AdOpenForwardOnly 默认值)打开仅向前类型游标。
1 AdOpenKeyset 打开键集类型游标。
2 AdOpenDynamic 打开动态类型游标。
3 AdOpenStatic 打开静态类型游标。LockType 可选。确定提供者打开 Recordset 时应该使用的锁定(并发)类型的 LockTypeEnum 值,可为下列常量之一(参见 LockType 属性可获得详细信息)。
值 常量 说明
--- -------------------------------- -----------------------
1 AdLockReadOnly (默认值)只读 — 不能改变数据。
2 AdLockPessimistic 保守式锁定,提供者完成确保成功编辑记录所需的工作,通常通过在编辑时立即锁定数据源的记录。
3 AdLockOptimistic 开放式锁定(逐个) — 提供者使用开放式锁定,只在调用Update 方法时才锁定记录。
4 AdLockBatchOptimistic 开放式批更新—用于批更新模式(与立即更新模式相对)。
3149是指未指定错误...
_RecordsetPtr 呢!
CString strSel = "select * from tblPerson";
_variant_t varSel(strSel);
_variant_t varConn(strConnect);他俩的值是这个啊
我直接这样做.居然是对的
CString strConnect="Provider = SQLOLEDB; Data Source = .; Initial Catalog = testDB; uid = sa; pwd = sa;";
CString strSel = "select * from tblPerson";
_variant_t varSel(strSel);
_variant_t varConn(strConnect); -->m_pRecordset->Open(varSel, _variant_t((IDispatch *)m_pConnection,adOpenKeyset, adLockOptimistic, adCmdUnkown),