>>>>>>>>

poweruser poweruser 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
能找到的例子都是vb的,在vb中可以不加参数,但是VC中就不行,谁有这方面的经验请
赐教!!!
每次编译可以通过,但是运行到open这一句就出错
代码如下
_bstr_t SQLxml;

try
{
m_connection.CreateInstance("ADODB.Connection");
m_command.CreateInstance("ADODB.Command");
m_strmIn.CreateInstance("ADODB.Stream");
m_strmOut.CreateInstance("ADODB.Stream");
m_recordset.CreateInstance("ADODB.Recordset");
m_record.CreateInstance("ADODB.Record");

//Open a conneciton to the SQL Server
//m_connection->Provider="SQLOLEDB";
_bstr_t sql;
sql="driver=sql server;server=yangys;database=test;uid=sa";
m_connection->Open(sql,"","",adModeUnknown);

m_command->ActiveConnection=m_connection;

//build the command string for a XML
SQLxml="<root xmlns:sql=""urn:schemas-microsoft-com:xml-sql""><sql:query><![CDATA[select * form employee for xml auto]]></sql:query></root>";

//Open the command stream and write our template to it
_bstr_t bstrUser="sa";
_bstr_t bstrPwd="";

m_strmIn->GetState(); // for test state

m_strmIn->Open //<<<<<< RUNTIME ERROR>>>>>>>("",adModeUnknown,adOpenStreamFromRecord,bstrUser,bstrPwd);
m_strmIn->WriteText(SQLxml,adWriteChar);
m_strmIn->Position=0;

//Execute the command,open the return stream,and read the result
m_strmOut->Open("",adModeUnknown,adOpenStreamAsync,"","");
m_strmOut->LineSeparator=adCRLF;

_variant_t rsAffect;

Properties* pProperties;
Property* pProperty;
_variant_t vtIndex;
vtIndex.vt=VT_I2;
m_command->get_Properties((Properties**)&pProperties);
pProperties->get_Item(vtIndex,(Property**)&pProperty);
pProperty->GetValue();

m_command->Execute(&rsAffect,NULL,adExecuteStream);

m_strmOut->Position=0;

运行到m_strmIn->Open这句时就会出错,是内存读取错误
请帮忙看看,谢谢!
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
poweruser
VC/MFC 16,550 成员 421,606 内容