_RecordsetPtr ACCESS 数据插入
_Connection已经连接好了的,用_RecordsetPtr修改字段的话也是可以的,但就是不能在空的表格中插入数据。空表名是收费表,字段有居民号,车辆号,入库时间,出库时间,办理人。插入数据代码如下:
try { CString sql; sql = "SELECT * FROM 收费表"; m_pRecordset.CreateInstance(__uuidof(Recordset)); m_pRecordset->Open((_variant_t)sql,((CCar_costApp*)AfxGetApp())->m_pConnection.GetInterfacePtr(), adOpenStatic,adLockOptimistic,adCmdText);// m_pRecordset->MoveLast(); m_pRecordset->AddNew(); m_pRecordset->PutCollect("居民号",_variant_t(m_dep_id)); m_pRecordset->PutCollect("车辆号",_variant_t(m_car_id)); m_pRecordset->PutCollect("入库时间",_variant_t(m_start_time)); m_pRecordset->PutCollect("办理人",_variant_t(m_use_id)); m_pRecordset->MoveNext(); m_pRecordset->Update(); AfxMessageBox("修改成功!"); m_pRecordset->Close(); }