这有一个aaa.dbf文件,(其实只是一个表),我在“控制面板”下的ODBC为其指定别名的时候,有些格式的驱动不能对其操作,比如,ACCESS和DBASE就不行,而VF 和 VFP就可以,在指定别名的时候,这两个驱动就会提示选择“Visual FoxPro database(.DBC)” 或 “Free Table directory”,当我选择后者时,就可以指定我的这个aaa.dbf了。问题是,我想对这个数据表文件操作(添加、删除):用VC的ClassWizard添加新类:CDataRecordset(CRecordset),直到最后定义其对象:
CDataRecordset *data;后面就是data->add();等等的数据库操作,编译正常,运行的时候,一到这个第一句“data->add();”时就有个提示框“'0x00401a84'指令引用的'0xcccccccccc'内存,该内存不能为'read'”,为什么啊??难道必须用DAO吗?
CDataRecordset *data;后面就是data->add();等等的数据库操作,编译正常,运行的时候,一到这个第一句“data->add();”时就有个提示框“'0x00401a84'指令引用的'0xcccccccccc'内存,该内存不能为'read'”,为什么啊??难道必须用DAO吗?
m_database=new CDatabase
if(!m_database->OpenNULL,FALSE,FALSE,sDSN,FALSE))
{
//AfxMessageBox("ODBC Connection Faile!");
CDialog::EndDialog(0);
GetParent()->PostMessage(WM_CLOSE);
return FALSE;
}
CString strSQL="select * from pdaa1";
data = new CDataRecordset(m_database);
data->Open(CRecordset::snapshot,strSQL);
#include "stdafx.h"
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
,"","",adConnectUnspecified);
pRst->Open("images", _variant_t((IDispatch *) pConn, true),
adOpenStatic, adLockReadOnly, adCmdTable);
FieldsPtr fds=pRst->GetFields();
printf("printf field name of all the table\n");
for(int i=0;i<fds->GetCount();i++)
{
FieldPtr fd=fds->GetItem(_variant_t(short(i)));
printf("%s ",(LPCTSTR)fd->GetName());
}
printf("\n");
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
return 0;
}
只有一次操作结束才可以更新
SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Visual FoxPro Driver", "DSN=data\0Description=data\0SourceType=dbf\0Source=e:\\conv\0"); m_database.Open(_T("data"));
data.m_pDatabase=&m_database;
data.Open(AFX_DB_USE_DEFAULT_TYPE, "SELECT * FROM 表" ,CRecordset::none);