808
社区成员




Dim conn As New ADODB.Connection
Dim path$
path = App.path & "\" 'path 是文件夹,Thumbs.db是文件名。表名是Thumbs
Call SetAttr(path, vbNormal)
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Extended Properties=Paradox 5.x;Persist Security Info=False"
conn.Open connstr
Debug.Print conn.State'成功
Dim rs As New Recordset
rs.Open "SELECT * FROM Thumbs", conn, 1, 1'失败。。。
Debug.Print rs.EOF
//找到一个C++的
//Thumbs.db 文件怎么打开
#include <stdlib.h>
#include <stdio.h>
#define NFIELDS 5
#define TRUE 1
#define FALSE 0
/* DBF文件头结构 */
struct dbf_head{
char vers;
unsigned char yy,mm,dd;
unsigned int no_recs;
unsigned short head_len,rec_len;
char reserved[20];
};
/* DBF字段描述结构 */
struct field_element{
char field_name[11];
char field_type;
unsigned int offset;
unsigned char field_length;
unsigned char field_decimal;
char reserved1[2];
char dbaseiv_id;
char reserved2[10];
char production_index;
};
char *dbf_fields_name[NFIELDS]={
"a", "b","c","d","e"
};
/* 全局变量 */
struct dbf_head file_head;
struct field_element *fields;
int *length;
unsigned int *offset;
/* 整形数字节顺序改变函数 */
void revert_unsigned_short(unsigned short *a)
{
unsigned short left,right;
left=right=*a;
*a=((left&0x00ff)<<8)|((right&0xff00)>>8);
}
void revert_unsigned_int(unsigned int *a)
{
unsigned int first,second,third,forth;
first=second=third=forth=*a;
*a=((first&0x000000ff)<<24)|((second&0x0000ff00)<<8)|
((third&0x00ff0000)>>8)|((forth&0xff000000)>>24);
}
/* 主函数代码 */
void main()
{
register int i,j;
FILE *fp_dat;
char *buffer;
char *allspace;
int fields_count, matched=FALSE;
unsigned int counts;
/* 打开dbf文件 */
if((fp_dat=fopen("a.dbf","rb"))==NULL){
fprintf(stderr,"Cannot open dbf file to read!\n");
exit(1);
}
/* 读取表头纪录 */
fseek(fp_dat,0L,SEEK_SET);
fread((void*)&file_head,sizeof(struct dbf_head),1,fp_dat);
revert_unsigned_int(&file_head.no_recs);
revert_unsigned_short(&file_head.head_len);
revert_unsigned_short(&file_head.rec_len);
/* 计算字段数 */
fields_count=(file_head.head_len-sizeof(struct dbf_head)-1-263)/sizeof(struct field_element);
/* 开辟存储字段子记录的空间 */
if((fields=(struct field_element*)malloc(sizeof(struct field_element)*fields_count))==NULL){
fprintf(stderr,"Cannot allocate memory for fields array !\n");
fclose(fp_dat);
exit(2);
}
/* 开辟存储一条数据记录的空间 */
if((buffer=(char*)malloc(sizeof(char)*file_head.rec_len))==NULL){
fprintf(stderr,"Cannot allocate memory for record buffer!\n");
fclose(fp_dat);
exit(3);
}
/* 开辟一个全为空格的纪录,以便后面做比较 */
if((allspace=(char*)malloc(sizeof(char)*file_head.rec_len))==NULL){
fprintf(stderr,"Cannot allocate memory for all_space record buffer!\n");
fclose(fp_dat);
exit(4);
}
else{
memset((void*)allspace,'\x20',file_head.rec_len-1);
allspace[file_head.rec_len]='\0';
}
/* 读取所有的字段子记录,调整整形数的字节顺序 */
fread((void*)fields,sizeof(struct field_element),fields_count,fp_dat);
for(i=0;i<fields_count;i++)
revert_unsigned_int(&fields[i].offset);
/* 计算各个字段的字节偏移量,第一字节为删除标记 */
fields[0].offset=1;
for(i=1;i<fields_count;i++)
fields[i].offset=fields[i-1].offset+(unsigned short)fields[i-1].field_length;
/* 开辟存储字段长度和偏移量的数组 */
length=(int*)malloc(sizeof(int)*fields_count);
offset=(unsigned int*)malloc(sizeof(unsigned int)*fields_count);
if(length==NULL||offset==NULL){
fprintf(stderr,"Cannot allocate memory for array length or offset.\n");
exit(-1);
}
/* 找到所需字段的偏移量和长度,如果没有相应字段,程序退出 */
for(i=0;i<NFIELDS;i++)
{
for(j=0;j<fields_count;j++)
{
if(strcmp(dbf_fields_name[i],fields[j].field_name)==0)
{
offset[i]=fields[j].offset - 1;
length[i]=fields[j].field_length;
matched=TRUE;
break;
}
if(!matched){
fprintf(stderr,"dbf file structure is invalid, field %s not found.\n", dbf_fields_name[i]);
exit(-1);
}
else
matched=FALSE;
}
}
/* 定位文件指针到数据记录的开始位置 */
fseek(fp_dat,(long)file_head.head_len,SEEK_SET);
/* 读取每条记录的字段数据 */
for(counts=0;counts<file_head.no_recs;counts++)
{
/* 如果有删除标记,跳到下一条记录 */
if(fgetc(fp_dat)==(int)'\x2a')
{
fseek(fp_dat,(int)file_head.rec_len-1,SEEK_CUR);
continue;
}
fread((void*)buffer,(int)file_head.rec_len-1,1,fp_dat);
buffer[file_head.rec_len]='\0';
/*去掉全为空格的记录行*/
if(strcmp(buffer,allspace)==0)
continue;
}
fclose(fp_dat);
/* 释放开辟的空间 */
free(buffer);
free(allspace);
free(offset);
free(length);
//一个c++语言编写的db程序