VC ODBC 更新数据表的有关问题
VC ODBC 更新数据表的问题:
VC ODBC 更新数据表的问题:
望高手帮忙.
BOOL CBDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString s;
m_Set=new CRecordset(&m_DB);
if(!m_DB.OpenEx(_T("DSN=股票模拟01DS"),0))//连接数据源
{
AfxMessageBox("打开数据源失败!!");//报告错误
return 0;
}
if(!m_Set->IsOpen())
{
m_Set->Open(CRecordset::dynaset,_T("Select * from S值表"));//选择数据表并打开
}
if(m_Set->IsEOF())//记录集是否为空
{
AfxMessageBox("记录集没有记录");
return 0;
}
//得到字段值:
m_Set->MoveFirst();//第一个记录
m_Set->GetFieldValue((short)1,s);//把第1 列(字段:"S值")赋给变量K
K=atoi(s);
K=K+1;
s.Format("%d", K);
m_Set->Open(CRecordset::dynaset,_T("update S值表 set s值="+s+" where 编号=1"));//这段代码-组建能通过,执行出错.
return TRUE; // return TRUE unless you set the focus to a control
}

------解决方案--------------------
CDBException 捕捉异常
另外你的程序有可能会导致内存泄漏
VC ODBC 更新数据表的问题:
望高手帮忙.
BOOL CBDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString s;
m_Set=new CRecordset(&m_DB);
if(!m_DB.OpenEx(_T("DSN=股票模拟01DS"),0))//连接数据源
{
AfxMessageBox("打开数据源失败!!");//报告错误
return 0;
}
if(!m_Set->IsOpen())
{
m_Set->Open(CRecordset::dynaset,_T("Select * from S值表"));//选择数据表并打开
}
if(m_Set->IsEOF())//记录集是否为空
{
AfxMessageBox("记录集没有记录");
return 0;
}
//得到字段值:
m_Set->MoveFirst();//第一个记录
m_Set->GetFieldValue((short)1,s);//把第1 列(字段:"S值")赋给变量K
K=atoi(s);
K=K+1;
s.Format("%d", K);
m_Set->Open(CRecordset::dynaset,_T("update S值表 set s值="+s+" where 编号=1"));//这段代码-组建能通过,执行出错.
return TRUE; // return TRUE unless you set the focus to a control
}
------解决方案--------------------
CDBException 捕捉异常
另外你的程序有可能会导致内存泄漏
try
{
}
catch(CDBException *e)
{
AfxMessageBox( e->m_strError, MB_ICONEXCLAMATION );
e->Delete();
}