简体   繁体   English

更新数据库MFC C ++ ODBC CRecordset

[英]Update Database MFC C++ ODBC CRecordset

I'm Developing a MFC application (SDI) to update, add and delete a table in the database called security. 我正在开发MFC应用程序(SDI),以更新,添加和删除数据库中称为安全性的表。 The problem is after updating one row in the table, the row is Updated ( i verified) then when I do another action (updating another row or deleting a row) the update is canceled. 问题是更新表中的一行后,该行被更新(我已验证),然后当我执行另一项操作(更新另一行或删除一行)时,更新被取消。 I really don't know if there is a problem with the CRecordset or the database itself. 我真的不知道CRecordset或数据库本身是否有问题。

//m_pSet is a an instance of a class based on CRecordSet:

m_pSet->Open();
m_pSet->Edit();
m_pSet->m_Security_Id = sec->SecurityId;
m_pSet->m_Security_Name = sec->SecurityName;
m_pSet->m_Security_Type_Id = sec->SecurityTypeStringToInt();
if (!m_pSet->Update())
{
    AfxMessageBox(_T("Record not updated; no field values were set."));
}

In my experiences with Oracle and SQL Server there is a difference in the way commit statements happen. 根据我在OracleSQL Server方面的经验, commit语句的发生方式有所不同。 The behavior you are seeing implies that the Update is not implicitly committed. 您看到的行为意味着Update不是隐式提交的。

In Oracle , commits are an explicit statement and need to be conducted after you have carried out some transaction. Oracle ,提交是一个明确的语句,需要在执行某些事务之后进行。

In SQL Server , commits are implicit by default and do not need to be carried out after transactions. SQL Server ,默认情况下,提交是隐式的,不需要在事务之后执行。

That being said, this other other Stack Overflow Question and Answer appears to have two methods of making commits explicit in SQL Server, meaning without the commit, you may lose your transaction. 话虽这么说,另一个其他堆栈溢出问题和答案似乎还有两种在SQL Server中显式进行提交的方法,这意味着如果没有提交,您可能会丢失事务。

The first being that you can use BEGIN TRANSACTION to have the database wait for a commit statement. 第一个是可以使用BEGIN TRANSACTION来使数据库等待commit语句。 From what you have posted, it would seem this is not the case. 从您发布的内容来看,情况似乎并非如此。

The other way to make commit statements explicit in SQL Server is by changing some settings on the databsae itself. 在SQL Server中使commit语句显式的另一种方法是通过更改databsae本身的某些设置。 Based on your line of thought I would check the settings referred to in the post noted here and ensure that you did not make commits implicit. 根据您的想法,我将检查此处提到的帖子中提到的设置,并确保您没有使提交隐式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM