如何用vc+ado动态创建sql server数据库,请高手指教

liufengping liufengping 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下是我写的代码,但是不行,请各位高手指教

//create a Connection
_ConnectionPtr pConnection;
pConnection.CreateInstance(__uuidof(Connection));
//crate a Command
_CommandPtr pCommand;
pCommand.CreateInstance(__uuidof(Command));
//create a connection string
CString sql="Provider=SQLOLEDB.1;Password=123;"
"Persist Security Info=True; User ID=sa;"
"Initial Catalog=Northwind; Data Source=LFP82\\LFP";

try
{
pConnection->Open(_bstr_t(sql),"","",adModeUnknown);
_variant_t vNULL;
vNULL.vt = VT_ERROR;
vNULL.scode = DISP_E_PARAMNOTFOUND;//define non_para
CString strcratedatabase = "crate database robin";
pCommand->ActiveConnection = pConnection;
pCommand->CommandText = _bstr_t(strcratedatabase);
pCommand->Execute(&vNULL,&vNULL,adCmdText);
pConnection->Close();
}
catch (_com_error* e)
{
AfxMessageBox(e->ErrorMessage());
}
catch(...)
{
//AfxMessageBox("")
}
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
liufengping
应用实例 27,579 成员 68,540 内容