对话框使用ODBC访问access数据库
在对话框中使用ODBC访问ACCESS数据库, 连接\查询都正常, 但是添加记录, 编辑记录等操作在Update时, 返回都是失败!
增加记录部分代码如下:
UpdateData(TRUE);
CString ID = this->m_ID;
CString Name = this->m_Name;
CString InTime = this->m_InTime;
CString OutTime = this->m_OutTime;
CString Department = this->m_Department;
this->m_RecordsetEmployee.AddNew();
this->m_RecordsetEmployee.m_ID = ID;
this->m_RecordsetEmployee.m_NAME = Name;
this->m_RecordsetEmployee.m_INTIME = InTime;
this->m_RecordsetEmployee.m_OUTTIME = OutTime;
this->m_RecordsetEmployee.m_DEPARTMENT = Department;
if( 0 == this->m_RecordsetEmployee.Update() )
{
::AfxMessageBox( "Fail to add new record!" );
}
this->m_RecordsetEmployee.Requery();
------解决方案--------------------
为什么不用ADO连接MDB
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\1.mdb
------解决方案--------------------
调试中看一下你的这些变量的内容是什么?
ID;Name;InTime;OutTime;Department;
估计有为空的,或者数据类型不符合的。