VC++用ADO连接数据库,登陆界面代码怎么写?在线等,急,高分
C++新手,要详细注释!谢谢啊!
VC++用ADO连接数据库,登陆界面代码怎么写?
答案:1 悬赏:40 手机版
解决时间 2021-04-10 08:34
- 提问者网友:雪舞兮
- 2021-04-10 05:32
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-04-10 06:29
1.提取单条记录
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; /
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; /
_ConnectionPtr Conn = NULL;
_RecordsetPtr Rs = NULL;
_CommandPtr Cmd = NULL;
CoInitialize(NULL);
Conn.CreateInstance (_uuidof(Connection));
Rs.CreateInstance (_uuidof(Recordset));
Cmd.CreateInstance (_uuidof(Command));
Conn->Open(L"db", L"sa", L"", adOpenUnspecified); //打开正常
//如下为_CommandPtr对象参数的赋值和调用
Cmd->ActiveConnection = Conn;
Cmd->CommandText = "SP_TEST";
//数据库中实际存在这个测试存储过程,select * from atable,不传递参数
Cmd->CommandType = adCmdStoredProc;
Cmd->Parameters->Refresh();
Rs = Cmd->Execute( NULL,NULL, adCmdUnknown ); //COM出错。
//注释掉的代码为直接的SQL语句提交,运行正确。
//Cmd->ActiveConnection=Conn;
//Cmd->CommandText = "select * from atable";
//Cmd->CommandType = adCmdText;
//Cmd->Parameters->Refresh();
//Rs = Cmd->Execute(NULL,NULL,adCmdUnknown);
Rs->Close();
Conn->Close();
CoUninitialize();
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; /
CoInitialize(NULL);
_bstr_t varSource="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%%0"; /
_ConnectionPtr Conn = NULL;
_RecordsetPtr Rs = NULL;
_CommandPtr Cmd = NULL;
CoInitialize(NULL);
Conn.CreateInstance (_uuidof(Connection));
Rs.CreateInstance (_uuidof(Recordset));
Cmd.CreateInstance (_uuidof(Command));
Conn->Open(L"db", L"sa", L"", adOpenUnspecified); //打开正常
//如下为_CommandPtr对象参数的赋值和调用
Cmd->ActiveConnection = Conn;
Cmd->CommandText = "SP_TEST";
//数据库中实际存在这个测试存储过程,select * from atable,不传递参数
Cmd->CommandType = adCmdStoredProc;
Cmd->Parameters->Refresh();
Rs = Cmd->Execute( NULL,NULL, adCmdUnknown ); //COM出错。
//注释掉的代码为直接的SQL语句提交,运行正确。
//Cmd->ActiveConnection=Conn;
//Cmd->CommandText = "select * from atable";
//Cmd->CommandType = adCmdText;
//Cmd->Parameters->Refresh();
//Rs = Cmd->Execute(NULL,NULL,adCmdUnknown);
Rs->Close();
Conn->Close();
CoUninitialize();
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯