Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to MS Access table using C++

Status
Not open for further replies.

thiru80

Programmer
Nov 13, 2002
4
US
I am trying to access a record of a table.I have written the follwoing code.But when I try to compile it gives some errors

fxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/ex.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

The following is the code I have written for it.
I would be glad if anyone can let me know if I need to change any settings.I m running it as a win32 Console application project

#include <iostream.h>
#include <stdlib.h>
#include <afx.h>


#define UC (char *)
#import &quot;c:\program files\common files\system\ado\msado15.dll&quot;rename(&quot;EOF&quot;,&quot;adoEOF&quot;) no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr = sp.CreateInstance( _uuidof(riid)); if (FAILED(_hr))_com_issue_error(_hr);}
#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value

struct InitOle{
InitOle(){::CoInitialize(NULL);}
~InitOle() {::CoUninitialize();}
}_init_InitOle;




void main()

{
int i,k;

_RecordsetPtr spRS;
_ConnectionPtr spCON;

try

{
CREATEiNSTANCE(spCON,Connection);
spCON->ConnectionString = L&quot;driver={sql server};SERVER=(local);Database=pubs;&quot;
L&quot;driver;PWD=;&quot;;
spCON->ConnectionString = L&quot;DRIVER = { Microsoft Access Driver (*.mdb)};&quot;
L&quot;DBQ=db1.MDB;DefaultDir=C:\\C++;&quot;;

CREATEiNSTANCE(spRS,Recordset);
spRS->PutRefActiveConnection(spCON);
spRS->Open(&quot;select * from Table1&quot;,vtMissing,adOpenKeyset,adLockBatchOptimistic,-1);
i=0;

while(spRS->adoEOF==false)

{
k = short (RsITEM(spRS,&quot;ID&quot;));
spRS->MoveNext();
i ++;
}

spRS->Close();

}

catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bs = _bstr_t(&quot;Error: &quot;) + _bstr_t (e.Error()) + _bstr_t(&quot; Msg: &quot;) + _bstr_t(e.ErrorMessage()) + _bstr_t(&quot;Description:&quot;) + _bstr_t(e.Description());

MessageBox(0,bs,bstrSource,MB_OK);
}

}


#undef UC

Thanks in advance
Thiru
 
Setup you project to use the multithreaded run-time library.

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top