dear all,

Im new in C++ programming. Recently, im doing a login page using Microsoft Visual C++ 2010 Express and Microsoft Access as database. Im trying to connect ODBC to my system but there was a lot of error occur. Can somebody explain me what my problems...


This is my code :

CString sSQLStmt ="SELECT * FROM aaa";
int bconnect;

CString str = "ODBC;DSN=xxxxx;UID=sa;PWD=pass;" ;

bconnect=cdb.Open(str);
if(!bconnect)
printf("failed");

else
printf("connection open successfully\n");

CRecordset rs(&cdb);

CString varValue;

CDBVariant varValue1;

_bstr_t eventTime;

rs.Open( CRecordset::forwardOnly, sSQLStmt );

short nFields = rs.GetODBCFieldCount( );
while( !rs.IsEOF( ) )
{

rs.GetFieldValue( "[column name]", varValue);
eventTime = varValue;
printf("eventTime: %s\n\n", varValue);
rs.MoveNext( );

}

rs.Close( );


Here is my errors:

1>------ Build started: Project: testing2, Configuration: Debug Win32 ------
1> testing2.cpp
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(256): warning C4129: 'D' : unrecognized character escape sequence
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(256): warning C4129: 'D' : unrecognized character escape sequence
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(256): warning C4129: 'd' : unrecognized character escape sequence
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(259): error C2065: 'CString' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(259): error C2146: syntax error : missing ';' before identifier 'sSQLStmt'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(259): error C2065: 'sSQLStmt' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(262): error C2065: 'CString' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(262): error C2146: syntax error : missing ';' before identifier 'str'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(262): error C2065: 'str' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(264): error C2065: 'cdb' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(264): error C2228: left of '.Open' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(264): error C2065: 'str' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(266): error C3861: 'printf': identifier not found
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(269): error C3861: 'printf': identifier not found
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(274): error C2065: 'CRecordset' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(274): error C2146: syntax error : missing ';' before identifier 'rs'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(274): error C2065: 'cdb' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(274): error C3861: 'rs': identifier not found
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(278): error C2065: 'CString' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(278): error C2146: syntax error : missing ';' before identifier 'varValue'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(278): error C2065: 'varValue' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(280): error C2065: 'CDBVariant' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(280): error C2146: syntax error : missing ';' before identifier 'varValue1'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(280): error C2065: 'varValue1' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(282): error C2065: '_bstr_t' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(282): error C2146: syntax error : missing ';' before identifier 'eventTime'
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(282): error C2065: 'eventTime' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(285): error C2065: 'rs' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(285): error C2228: left of '.Open' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(285): error C2653: 'CRecordset' : is not a class or namespace name
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(285): error C2065: 'forwardOnly' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(285): error C2065: 'sSQLStmt' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(288): error C2065: 'rs' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(288): error C2228: left of '.GetODBCFieldCount' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(289): error C2065: 'rs' : undeclared identifier
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(289): error C2228: left of '.IsEOF' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\user\my documents\visual studio 2010\projects\testing2\testing2\Form1.h(289): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


can anyone know how to solve this prob??? plz......

Recommended Answers

All 5 Replies

The code you posted makes no sense all with the error messages. Post the code that correspoinds to the error messages.

I'm a rank amateur in terms of databases but overall it looks to me like you are trying to compile MFC code with the express edition which does not come with that feature.

I'm a rank amateur in terms of databases but overall it looks to me like you are trying to compile MFC code with the express edition which does not come with that feature.

You are right -- CRecordset is not supported by the Express edition.

@slowlearner: Create your own c++ class or a structure to contain the data for a single row of the resultset. Then use ODBC calls to iterate through the resultset rows.

Hi Guys,

Can you please specify which database you are using?

It doesn't matter -- use any SQL compliant database you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.