关于VS2015运用ADO连接access数据库问题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Interneting_Plus/article/details/95314709

ado连接数access据库首先就是添加msado15.dll文件的问题,可以用相对路径把msado15.dll文件复制到项目文件夹里,然后在

stdafx.h最后一句加上#import "msado15.dll" no_namespace rename("EOF", "adoEOF"),或者用相对路径#import "C:\Program Files (x86)\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF"),=======重点强调,32位系统的msado15.dll文件在C:\Program Files \Common Files\System\ado\msado15.dll,64位系统在C:\Program Files (x86)\Common Files\System\ado,如果是64位系统在调试的时候生成的debug也要选择64位,否则将会报错!!!!其他的连接函数和操作直接百度其他大佬的都可以

展开阅读全文

高分请教ADO连接ACCESS数据库问题

05-26

我这里有一个小程序是从WEB页里提取标题、内容、时间、来源等的,但是我要把这些内容提取到一个ACCESS数据库里的指定位置,该怎么做呢, 能否给出具体步骤或源代码呢?我知道用到ADO的相关内容,但是我不知道具体该怎没办,各位老大帮帮忙了谢谢!rn程序:rn#include "stdio.h"rn#include "stdlib.h"rn#include "ctype.h"rnrn#define T_NULL 0rn#define T_TITLE 1rn#define T_CONTEXT 2rn#define T_SOURCE 3rn#define T_DATE 4rnrnstruct Nodern char text;rn struct Node *next;rn;rnrnstruct Node *create(int i)rnrn struct Node *head,*p,*q;rn int j;rn for(j=0;jnext=q;rn p=q;rn rn rn p->next=head;rn return(head);rnrnrnvoid main()rnrn FILE *fp,*fp1;rn struct Node *sp,*head,*p,*q;rn char *ofname,*sfname,*types,ch;rn char titles[8]='<','T','I','T','L','E','>','\0',titles1[8];rn char Srcs[11]='h','r','e','f','=','h','t','t','p',':','\0';rn char Return='\n';rn char type[15];rn int i,k,flag,flag1=0,flag2=0,flag3=0,T_FLAG=T_NULL;rn ofname=(char *)calloc(20,1);rn sfname=(char *)calloc(20,1);rn types=(char *)calloc(10,1);rn printf("Enter the type of the web:");rn scanf("%s",type);rn printf("Enter the name of opened file:");rn scanf("%s",ofname);rn printf("Enter the name of saved file:");rn scanf("%s",sfname);rn if((fp=fopen(ofname,"r"))==NULL)rn rn printf("\ncann't open the file.\n");rn return;rn rnrn if((fp1=fopen(sfname,"w+"))==NULL)rn rn printf("\ncann't open the file.\n");rn return;rn rnrn types="类型:\0";rn for(i=0;types[i]!='\0';i++)rn fwrite(&types[i],1,1,fp1);rn for(i=0;type[i]!='\0';i++)rn fwrite(&type[i],1,1,fp1);rn fwrite(&Return,1,1,fp1);rn rn k=2;rn for(i=0;i<7;i++)rn titles1[i]=(char)tolower((int)titles[i]);rn head=sp=create(20);rn dorn rn switch(T_FLAG)rn rn case T_NULL:rn fread(&sp->text,1,1,fp);rnrn //find the timern if(sp->text=='t')rn rn p=head;rn while(p!=sp)rn rn if(p->text==' '&&p->next->text=='a'&&p->next->next->text=='t'&&p->next->next==sp)rn rn T_FLAG=T_DATE;rn head=sp->next;rn break;rn rn p=p->next;rn rn rnrn //find the sourcern if(sp->text==':')rn rn p=head;rn while(p!=sp)rn rn if(p->text==Srcs[0]&&p->next->text==Srcs[1])rn rn flag=1;rn q=p->next->next;rn for(k=2;k<10;k++,q=q->next)rn if(q->text!=Srcs[k])rn rn flag=0;rn break;rn rn if(flag)rn rn T_FLAG=T_SOURCE;rn head=sp;rn break;rn rn rn p=p->next;rn rn rnrn if(sp->text=='>')rn rn while(head!=sp)rn if(head->text!='<')rn head=head->next;rn elsern rn //find the titlernrn //capitalrn p=head->next;rn if(p->text==titles[1])rn rn flag=1;rn p=p->next;rn for(k=2;k<7;k++,p=p->next)rn if(p->text!=titles[k])rn rn flag=0;rn break;rn rn if(flag)rn rn T_FLAG=T_TITLE;rn head=p->next;rn break;rn rn rnrn //lowerrn p=head->next;rn if(p->text==titles1[1])rn rn flag=1;rn p=p->next;rn for(k=2;k<7;k++,p=p->next)rn if(p->text!=titles1[k])rn rn flag=0;rn break;rn rn if(flag)rn rn T_FLAG=T_TITLE;rn head=p->next;rn break;rn rn rnrnrn //find the contextrn p=head->next;rn if(p->text=='p'&&p->next->text=='>')rn rn T_FLAG=T_CONTEXT;rn head=p->next->next;rn break;rn rnrn p=head->next;rn if(p->text=='P'&&p->next->text=='>')rn rn T_FLAG=T_CONTEXT;rn head=p->next->next;rn break;rn rnrnrn head=head->next;rn rn rn sp=sp->next;rn break;rn default:rn switch(T_FLAG)rn rn case T_TITLE:rn if(!flag3)rn rn types="标题:\0";rn i=0;rn while(types[i]!='\0')rn rn fwrite(&types[i],1,1,fp1);rn i++;rn rn while(1)rn rn fread(&ch,1,1,fp);rn if(ch=='<')rn break;rn fwrite(&ch,1,1,fp1);rn rn fwrite(&Return,1,1,fp1);rn rn flag3=1;rn rn T_FLAG=T_NULL;rn break;rn case T_CONTEXT:rn if(flag1==0)rn types="正文:\0";rn elsern types=" \0";rn i=0;rn while(types[i]!='\0')rn rn fwrite(&types[i],1,1,fp1);rn i++;rn rn while(1)rn rn fread(&ch,1,1,fp);rn if(ch=='<')rn rn sp->text=ch;rn break;rn rn fwrite(&ch,1,1,fp1);rn rn fwrite(&Return,1,1,fp1);rn T_FLAG=T_NULL;rn flag1=1;rn break;rn case T_SOURCE:rn if(flag2==0)rn types="来源:http\0";rn elsern types=" http\0";rn i=0;rn while(types[i]!='\0')rn rn fwrite(&types[i],1,1,fp1);rn i++;rn rn while(1)rn rn fread(&ch,1,1,fp);rn if(ch=='<')rn rn sp->text=ch;rn break;rn rn fwrite(&ch,1,1,fp1);rn rn fwrite(&Return,1,1,fp1);rn T_FLAG=T_NULL;rn flag2=1;rn break;rn case T_DATE:rn types="时间:\0";rn i=0;rn while(types[i]!='\0')rn rn fwrite(&types[i],1,1,fp1);rn i++;rn rn while(1)rn rn fread(&ch,1,1,fp);rn if(ch=='F')rn rn sp->text=ch;rn break;rn rn fwrite(&ch,1,1,fp1);rn rn fwrite(&Return,1,1,fp1);rn T_FLAG=T_NULL;rn break;rn rn rn while(!feof(fp));rn rn for(i=0;i<19;i++)rn rn p=head->next;rn free(head);rn head=p;rn rn rnrn 论坛

ADO无法连接access数据库问题

09-22

我写了一个mfc程序,是sdi的。视图是Cformview的派生类。rn我想实现任意连接数据库的功能。所以在视图上添加了一个按钮。点击按钮,打开对话框选择数据库进行连接。代码如下所示:rnrn我先在stdafx.h文件中加了这句代码: rn#import "c:\program files\common files\system\ado\msado15.dll" \ rnno_namespace \ rnrename ("EOF", "adoEOF") rnrn接着我在CFormView的派生类中定义 rn// 定义ADO连接、命令、记录集变量指针 rn_ConnectionPtr m_pConnection; rn_CommandPtr m_pCommand; rn_RecordsetPtr m_pRecordset; rnrn然后在CMy3App中定义rn// 定义ADO连接变量指针rn _ConnectionPtr m_pConnection;rnrn接着在BOOL CMy3App::InitInstance()中添加如下代码:rn// 初始化COM,创建ADO连接等操作rn AfxOleInit();rn m_pConnection.CreateInstance(__uuidof(Connection));rnrn // 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,rn // 因为它有时会经常出现一些想不到的错误。jingzhou xurn if(SUCCEEDED(m_pConnection.CreateInstance(__uuidof(Connection) ))) rn rn m_pConnection->CursorLocation=adUseClient; //游标类型 rn rn rn最后在视图类的onbutton事件中添加如下代码:rnvoid CMy3View::Onbutton() rn rn CString dstSrc,Src,trc;rn Src="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";rn CFileDialog fileDlg(TRUE);rn if(IDOK == fileDlg.DoModal())rn rn dstSrc = fileDlg.GetPathName();rn rn rn dstSrc.Replace("\\", "\\\\" );rn trc=Src+dstSrc;rn _bstr_t q;rn q=trc;rn try rn rn // 打开本地Access库rn m_pConnection->Open(q,"","",adModeUnknown);rn rn rn catch(_com_error e)rn rn AfxMessageBox("数据库连接失败,确认数据库是否在当前路径下!");rn rn rnrn不知道哪里有问题,每次总是显示("数据库连接失败,确认数据库是否在当前路径下!");rn请大家指点一下,谢谢 论坛

ado连接数据库问题求救!!!

11-25

问题1:创建一个ADO数据库应用工程,代码如下:rnvoid CExample51View::OnInitialUpdate()rnrn CView::OnInitialUpdate();rn HRESULT hr;rn tryrn rn hr=m_pConnection.CreateInstance("ADODB.Connection");rn //创建Connection对象rn if(SUCCEEDED(hr))rn rn hr=m_pConnection->Open("Provider=SQLOLEDB.1;DataSource=DB100.mdf",rn "","",adModeUnknown); //连接数据库rn rn rn catch(_com_error e)rn rn CString errormessage;rn errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());rn AfxMessageBox(errormessage);rn rnrnrn运行时出现以下错误:rn--------------------Configuration: Example51 - Win32 Debug--------------------rnLinking...rnExample51View.obj : error LNK2005: "class _com_ptr_t > m_pConnection" (?m_pConnection@@3V?$_com_ptr_t@V?$_com_IIID@U_Connection@@$1?_GUID_00000550_0000_0rn010_8000_00aa006d2ea4@@3U__s_GUID@@A@@@@A) already defined in Example51.objrnDebug/Example51.exe : fatal error LNK1169: one or more multiply defined symbols foundrn执行 link.exe 时出错.rnrnExample51.exe - 1 error(s), 0 warning(s)rn============================================================================================================================================================================================================rn问题2:rn用ADO在工程中创建新表:按下按钮后新表就创建,代码如下:rnvoid CEX_Database06Dlg::OnNewtableButton() rnrn // TODO: Add your control notification handler code herern _ConnectionPtr m_pConnection;rn HRESULT hr;rn tryrn rn hr=m_pConnection.CreateInstance("ADODB.Connection");rn if(SUCCEEDED(hr))rn rn hr=m_pConnection->Open("Provider=SQLOLEDB.1;Data Source=DB100.mdf","","",adModeUnknown);rn rn rn catch(_com_error *e)rn rn CString errormessage;rn errormessage.Format("连接数据库失败:%s",e->ErrorMessage());rn AfxMessageBox(errormessage);rn rn _variant_t RecordsAffected;rn m_pConnection->Execute("CREATE TABLE StudentInfo(StuNo INTEGER,StuAge INTEGER)",rn &RecordsAffected,adCmdText);rnrnrn点击按钮后出现(提示框):rnRuntime Error!rnProgram:H:\......\EX_Database06.exernThis application has requested the runtime to terminated it in an unusual way.rnPlease contact the application's support team for more information.rnrn刚用ADO,对这些出现的问题总是找不到门,麻烦大家帮我看看。谢谢。 论坛

没有更多推荐了,返回首页