posts - 54, comments - 32, trackbacks - 0, articles - 0

数据库完整操作

Posted on 2007-03-28 16:22 宋鹏 阅读(1439) 评论(6)  编辑 收藏 引用 所属分类: 数据库
数据库完整操作
//定义变量
// build database
CEGUID m_ceguid;
HANDLE m_hdb=0;
CEOID m_ceoid=0;
TCHAR DBFILENAME[20] = _T("\\abc.db");
TCHAR DBTABLENAME[20] = _T("\\wang");

//insert database
CEOID ceoid =0;
CEPROPVAL * pRorps;
pRorps = new CEPROPVAL[2];

//read data
int iRecordCount;
CEOIDINFO oidinfo;
DWORD dwIndex;
DWORD dwRecSize;
WORD wProps;
PBYTE pBuff;
PCEPROPVAL pRecord;
int i;
int k;
//开始使用
case IDC_INSERT://CREATE DATABASE

//1. ¹ÒÔØÊý¾Ý¿â£¬²»´æÔÚÔò½¨Á¢
if (!CeMountDBVol(&m_ceguid,DBFILENAME,OPEN_ALWAYS))
{
MessageBox(NULL,TEXT("faile"),NULL,MB_OK);
return 0;
}
else
MessageBox(NULL,TEXT("build DB success"),NULL,MB_OK);
//2. ´ò¿ª±í£¬
m_hdb = CeOpenDatabaseEx(&m_ceguid,&m_ceoid,DBTABLENAME,NULL,
CEDB_AUTOINCREMENT,NULL);
if (m_hdb == INVALID_HANDLE_VALUE)
{
//3. ²»´æÔÚÔò½¨Á¢
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
CEDBASEINFO cedbaseinfo;
cedbaseinfo.dwFlags = CEDB_VALIDNAME | CEDB_VALIDTYPE
| CEDB_VALIDSORTSPEC;
wcscpy(cedbaseinfo.szDbaseName,DBTABLENAME);
cedbaseinfo.dwDbaseType = 0;
cedbaseinfo.wNumSortOrder = 1 ;//ÅÅÐòÊýÄ¿
cedbaseinfo.rgSortSpecs[0].propid = pid_no;
cedbaseinfo.rgSortSpecs[0].dwFlags = CEDB_SORT_CASEINSENSITIVE;

//
m_ceoid = CeCreateDatabaseEx(&m_ceguid,&cedbaseinfo);
if(m_ceoid==0)
MessageBox(NULL,TEXT("faile"),NULL,MB_OK);
else
{
m_hdb = CeOpenDatabaseEx(&m_ceguid,&m_ceoid,DBTABLENAME,NULL,
CEDB_AUTOINCREMENT,NULL);
MessageBox(NULL,TEXT("build table success"),NULL,MB_OK);
}
}


}
else
MessageBox(NULL,TEXT("open table success"),NULL,MB_OK);

///insert record

//
memset(pRorps,0,LocalSize(pRorps));
pRorps->propid = pid_no;
pRorps->val.lpwstr = TEXT("1");
//
pRorps ++;
//memset(pRorps,0,LocalSize(pRorps));
pRorps->propid = pid_name;
pRorps->val.lpwstr = TEXT("wang");

pRorps --;

ceoid = CeWriteRecordProps(m_hdb,0,2,pRorps);

if (ceoid == 0)
MessageBox(NULL,TEXT("insert failues"),NULL,MB_OK);
else
MessageBox(NULL,TEXT("insert success"),NULL,MB_OK);

//read record
//iRecordCount = CeGetRecordCount(&m_ceguid,m_ceoid);
CeOidGetInfoEx(&m_ceguid,m_ceoid,&oidinfo);
iRecordCount = oidinfo.infDatabase.wNumRecords;
wsprintf(DBTABLENAME,TEXT("RECORD IS %d"),iRecordCount);
MessageBox(NULL,DBTABLENAME,NULL,NULL);
//
for( i=0;i
{
ceoid =CeSeekDatabase(m_hdb,CEDB_SEEK_BEGINNING,i,&dwIndex);

pBuff=0;
ceoid=CeReadRecordProps(m_hdb,
CEDB_ALLOWREALLOC,
&wProps,
NULL,
& (LPBYTE)pBuff,
&dwRecSize);
pRecord =(PCEPROPVAL)pBuff;
//
for(k=0;k
{
switch(pRecord->propid)
{
case pid_no:
wcscpy(DBTABLENAME,pRecord->val.lpwstr);
MessageBox(NULL,DBTABLENAME,TEXT("NO"),NULL);

break;
//
case pid_name:
wcscpy(DBTABLENAME,pRecord->val.lpwstr);
MessageBox(NULL,DBTABLENAME,TEXT("NAME"),NULL);

break;
}
pRecord++;
}//

LocalFree(pBuff);
}
//delete
ceoid = CeSeekDatabase(m_hdb,CEDB_SEEK_BEGINNING,2,NULL);
if( CeDeleteRecord(m_hdb,ceoid))
MessageBox(NULL,_T("DELE success"),NULL,NULL);

if(CloseHandle(m_hdb))
MessageBox(NULL,_T("close success"),NULL,NULL);

if(CeUnmountDBVol(&m_ceguid))
MessageBox(NULL,_T("unmount success"),NULL,NULL);


//search


break;

Feedback

# re: 数据库完整操作 [未登录]  回复  更多评论   

2007-04-10 11:17 by RAINBOW
请问实现排序的函数是哪个?

# re: 数据库完整操作 [未登录]  回复  更多评论   

2007-04-10 11:19 by RAINBOW
WINCE自带的数据库里面已提供了四种排序方法,还需要另外做排序方法吗?

# re: 数据库完整操作 [未登录]  回复  更多评论   

2007-04-10 11:25 by RAINBOW
能给我点建诡议吗?

# re: 数据库完整操作 [未登录]  回复  更多评论   

2007-04-10 11:26 by RAINBOW
我收藏了你的博客!你的回复我可以看到!

# re: 数据库完整操作   回复  更多评论   

2007-04-11 10:22 by 宋鹏
应该不用别的了吧,我有个书里面带的例程,你要不要

# re: 数据库完整操作 [未登录]  回复  更多评论   

2007-04-19 20:47 by RAINBOW
是《EVC高级编程及其应用开发》这本书上的吗?
有没有导出数据库记录到向量中的方法?

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理