Click here to Skip to main content
15,922,533 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralVisual Studio 6 template support Pin
Antti Keskinen20-Oct-04 23:42
Antti Keskinen20-Oct-04 23:42 
GeneralRe: Visual Studio 6 template support Pin
Michael Dunn21-Oct-04 2:41
sitebuilderMichael Dunn21-Oct-04 2:41 
GeneralNeed a Step-by-step of how to sign an ActiveX Pin
anderslundsgard20-Oct-04 23:41
anderslundsgard20-Oct-04 23:41 
GeneralSetting temporary file path Pin
Vinaya20-Oct-04 23:21
Vinaya20-Oct-04 23:21 
GeneralRe: Setting temporary file path Pin
David Crow21-Oct-04 2:32
David Crow21-Oct-04 2:32 
Generallinking a microsoft access database to a vc++ program Pin
Anonymous20-Oct-04 23:17
Anonymous20-Oct-04 23:17 
GeneralRe: linking a microsoft access database to a vc++ program Pin
David Crow21-Oct-04 2:32
David Crow21-Oct-04 2:32 
GeneralRe: linking a microsoft access database to a vc++ program Pin
Vikram Kashyap21-Oct-04 3:33
Vikram Kashyap21-Oct-04 3:33 
Hi,

If you are using MFC, then u can use the following code to connect to access database.

<code>
BOOL CMyDatabaseTesting::ConnectToDatabase()
{
if(!m_pdb)
m_pdb = new CDatabase;

CString StrConnectString;
try
{
//Two Methods of connecting
//1. Through the database path as described below
//2. Using DSN, i.e, "DSN=szDSN;UID=szUsername;PWD=szPassword;

StrConnectString.Format("Driver={Microsoft Access Driver (*.mdb)};Dbq=%s;UID=%s;PWD=%s",strDBPath/*Contains the database path*/, "Admin",szPassword/*Password of database (fi any)*/);
m_pdb->OpenEx(StrConnectString,CDatabase::noOdbcDialog);
}
catch(CDBException *e)
{
if(e->m_strError.Find("Login failed") != -1)
{
MessageBox(0, e->m_strError, "Error1", MB_OK);
return FALSE;
}
else if((e->m_strError.Find("Server user id") != -1)
&& (e->m_strError.Find("is not a valid user in database") != -1))
{
MessageBox(0, e->m_strError, "Error2", MB_OK);
return FALSE;
}
else if(e->m_strError.Find("Data source name not found and no default driver specified") != -1)
{
MessageBox(0, e->m_strError, "Error3", MB_OK);
e->Delete();
if(m_pdb)
{
if(m_pdb->IsOpen())
m_pdb->Close();
delete m_pdb;
m_pdb = NULL;
}
return FALSE;
}
else
{
//Database related error
MessageBox(0, e->m_strError, "Database Error", MB_OK);
return FALSE;
}
if(m_pdb)
{
if(m_pdb->IsOpen())
m_pdb->Close();
delete m_pdb;
m_pdb = NULL;
}
e->Delete();
return FALSE;
}
return TRUE;
}
</code>

Where m_pdb is a pointer to CDatabase. Also don't forget to include <afxdb.h> in stdafx.h file. That's it, you are connect to the database.

Enjoy...

WTF | :WTF:

Vikram Kashyap
"You will never fail until you stop trying"
GeneralA problem with update application. Please help me ! Pin
King of Merit20-Oct-04 22:51
King of Merit20-Oct-04 22:51 
GeneralRe: A problem with update application. Please help me ! Pin
ThatsAlok20-Oct-04 23:52
ThatsAlok20-Oct-04 23:52 
QuestionHow to execute command line in remote machine? Pin
dungle3020-Oct-04 22:33
dungle3020-Oct-04 22:33 
AnswerRe: How to execute command line in remote machine? Pin
ThatsAlok21-Oct-04 0:41
ThatsAlok21-Oct-04 0:41 
AnswerRe: How to execute command line in remote machine? Pin
Henry miller21-Oct-04 2:26
Henry miller21-Oct-04 2:26 
AnswerRe: How to execute command line in remote machine? Pin
David Crow21-Oct-04 2:37
David Crow21-Oct-04 2:37 
GeneralRe: How to execute command line in remote machine? Pin
dungle3021-Oct-04 16:47
dungle3021-Oct-04 16:47 
GeneralWindows message with MFC Pin
madretierra20-Oct-04 22:15
madretierra20-Oct-04 22:15 
GeneralRe: Windows message with MFC Pin
David Crow21-Oct-04 2:39
David Crow21-Oct-04 2:39 
GeneralRe: Windows message with MFC Pin
Anonymous21-Oct-04 4:33
Anonymous21-Oct-04 4:33 
GeneralRe: Windows message with MFC Pin
David Crow21-Oct-04 4:37
David Crow21-Oct-04 4:37 
GeneralRe: Windows message with MFC Pin
madretierra21-Oct-04 4:53
madretierra21-Oct-04 4:53 
GeneralRe: Windows message with MFC Pin
David Crow21-Oct-04 5:25
David Crow21-Oct-04 5:25 
GeneralRe: Windows message with MFC Pin
madretierra21-Oct-04 5:40
madretierra21-Oct-04 5:40 
GeneralMFC List Control Pin
missnazar20-Oct-04 21:03
missnazar20-Oct-04 21:03 
GeneralRe: MFC List Control Pin
David Crow21-Oct-04 2:42
David Crow21-Oct-04 2:42 
Generali want c++code for simple calender Pin
mohamed radwan20-Oct-04 20:11
mohamed radwan20-Oct-04 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.