帮我看看写数据库的代码,为什么写不成功?

taianmonkey 2003-12-14 05:39:06
已经初试化COM!

if(lstrlen(chDataSource)<=0) return ;
if(lstrlen(chSqlSentence)<=0) return ;

IADORecordBinding *picRs = NULL;
_RecordsetPtr pRs("ADODB.Recordset");
_ConnectionPtr pConn("ADODB.Connection" );
CFootballTeamRs rsFootballTeam;

pConn->ConnectionString = chDataSource;
pConn->Provider = _T("Microsoft.Jet.OLEDB.4.0");

try
{
pConn->Open(pConn->ConnectionString, "", "", adModeUnknown);


pRs->QueryInterface(
__uuidof(IADORecordBinding), (LPVOID*)&picRs);

pRs->Open( (_variant_t)chSqlSentence, // 查询DemoTable表中所有字段
pConn.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
TESTHR(picRs->BindToRecordset(&rsFootballTeam));
}
catch (_com_error &e)
{
sprintf(errMsg,_T("Code meaning = %s\n"), (char*) e.ErrorMessage());
AfxMessageBox(errMsg);
return;
}

try
{
pRs->MoveLast();
}
catch (_com_error &e)
{
sprintf(errMsg,_T("Code meaning = %s\n"), (char*) e.ErrorMessage());
AfxMessageBox(errMsg);
return;
}

rsFootballTeam.m_Age = GetDlgItemInt(IDC_AGE);
rsFootballTeam.m_AttendNationNums = GetDlgItemInt(IDC_NATIONAL);
rsFootballTeam.m_Def = GetDlgItemInt(IDC_DEF);
rsFootballTeam.m_DoorFell = GetDlgItemInt(IDC_DOORFELL);
rsFootballTeam.m_FarShot = GetDlgItemInt(IDC_FAR_SHOT);
rsFootballTeam.m_Illness = GetDlgItemInt(IDC_ILLNESS);
// CString strName;
// TCHAR Name[MAX_PATH];
::GetDlgItemText(m_hWnd,IDC_NAME,rsFootballTeam.m_Name,MAX_PATH);
/* lstrcpy(Name, strName);
rsFootballTeam.m_Name = Name;*/
rsFootballTeam.m_Stature = GetDlgItemInt(IDC_STATURE);

try
{
picRs->AddNew(&rsFootballTeam);
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
::MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );

TESTHR(picRs->Update(&rsFootballTeam));
}
catch (_com_error &e)
{
sprintf(errMsg,_T("Code meaning = %s\n"), (char*) e.ErrorMessage());
AfxMessageBox(errMsg);
return;
}
...全文
58 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
taianmonkey 2003-12-24
  • 打赏
  • 举报
回复
解决了!
crystal_heart 2003-12-16
  • 打赏
  • 举报
回复
up
cdwy411 2003-12-16
  • 打赏
  • 举报
回复
那就是帮定有问题了哦?
可以跟踪看看!
taianmonkey 2003-12-14
  • 打赏
  • 举报
回复
用PutCollect()可以实现!
为什么绑定后为什么不能实现?

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧