我想更新数据在一个表里,但表里的值总是不变,请大家看看是什么原因????谢谢我用的是vc --- SQL Server2000 ---- ADO方式//////////////////////////在OnInitDialog()中添加: strCnn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sqlserver;Initial Catalog=server_data;Data Source=(local)"; m_pConnection.CreateInstance(__uuidof(Connection)); //创建connection对象实例
m_pConnection->Open((_bstr_t)strCnn, "", "", adModeUnknown);///////////////////////////////////////////void CSERVERDlg::DBUpdateAccount(char account[16])
{ try{
CString sTime = GetCurrentTime(); //得到当前时间 char tmp[256];
_variant_t RecordsAffected;
memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "UPDATE Account set time=%s where account=%s", sTime,account);
m_pConnection->Execute(tmp, &RecordsAffected, adCmdText); ?????????调试时运行到这里就跳到catch里了,上一步的tmp的值是正确的.
}catch(_com_error &e)
{
::MessageBox(NULL,e.Description(),"更新错误",MB_OK);
}}/////////////////////////////////////////////////在程序中调用:
DBUpdateAccount(m_Account);
m_pConnection->Open((_bstr_t)strCnn, "", "", adModeUnknown);///////////////////////////////////////////void CSERVERDlg::DBUpdateAccount(char account[16])
{ try{
CString sTime = GetCurrentTime(); //得到当前时间 char tmp[256];
_variant_t RecordsAffected;
memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "UPDATE Account set time=%s where account=%s", sTime,account);
m_pConnection->Execute(tmp, &RecordsAffected, adCmdText); ?????????调试时运行到这里就跳到catch里了,上一步的tmp的值是正确的.
}catch(_com_error &e)
{
::MessageBox(NULL,e.Description(),"更新错误",MB_OK);
}}/////////////////////////////////////////////////在程序中调用:
DBUpdateAccount(m_Account);
解决方案 »
- 理解TCP/IP协议对socket编程有什么作用
- 请教高手,一个关于VC程序运行无法响应的问题
- 单文档界面设计
- 我在ListCtrl中用SHGetFilelnfo插入系统图标为什么关闭后第二次打开就没有图标了
- 不知道为啥,SQL中的WHERE不好用啊
- 请教关于船用古野F站的计时/计流量的问题。
- Socket TCP 的问题,前辈们请进!
- MFC 將COMBOBOX內的值傳到CHILDVIEW內
- 关于在动态链接库中输出资源的问题,一定结帐
- 6个vc初学者易遇到的问题,望各位不吝指教!!(最后的分数悉数奉上)
- 如何把BYTE型数组转换成CString类型?
- 请问一下,可以通过甚么来得到使用文件的进程?
改成这样试试看看
就要
CTime t = CTime::GetCurrentTime();
CString sTime = t.Format( "%Y-%m-%d %H:%M:%S" );//"2006-11-01 12:30:20"
.....sprintf(tmp, "UPDATE Account set time='%s' where account='%s'", sTime,account);
注意要加单引号
对了,谢谢.是因为没有加update中没有加 '' 的原因,你后面说的我是这么做的.say thanks again!