Click here to Skip to main content
15,888,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralIterator Pin
Andre Pham29-Dec-03 8:31
Andre Pham29-Dec-03 8:31 
GeneralRe: Iterator Pin
Rafael Fernández López29-Dec-03 10:55
Rafael Fernández López29-Dec-03 10:55 
GeneralRe: Iterator Pin
Jörgen Sigvardsson29-Dec-03 11:10
Jörgen Sigvardsson29-Dec-03 11:10 
GeneralPassing DB handle between applications Pin
Member 56390729-Dec-03 8:29
Member 56390729-Dec-03 8:29 
GeneralRe: Passing DB handle between applications Pin
David Crow29-Dec-03 8:35
David Crow29-Dec-03 8:35 
GeneralRe: Passing DB handle between applications Pin
Brian Shifrin29-Dec-03 10:39
Brian Shifrin29-Dec-03 10:39 
GeneralRe: Passing DB handle between applications Pin
Jörgen Sigvardsson29-Dec-03 11:13
Jörgen Sigvardsson29-Dec-03 11:13 
Generaldatabase error Pin
ansontong29-Dec-03 7:41
ansontong29-Dec-03 7:41 
Dear friend,

I met a database assert error when I execute my program. My coding is
//======================= main.cpp=============================
//-------------------------------------------------------------
// optional information, such as a user ID and password.
// For example, "DSN=SQLServer_Source;UID=SA;PWD=abc123"
//
BOOL OpenDataBase(CDatabase *db)
{
CString connect;
BOOL openOK;

openOK = TRUE;

connect += "UID=Admin;";
connect += "PWD=anson;"; // Password of file is anson
connect += "DRIVER={Microsoft Access Driver (*.mdb)};";
connect += "DBQ=";
connect += "./database/pmsdb.mdb";

char teststr[255];
try
{ db->OpenEx(connect, CDatabase::noOdbcDialog);
}
catch ( CDBException* e)
{
MessageBox(NULL, "DataBase file error.", "PMS Error
Message", MB_OK);
e->GetErrorMessage(teststr, 255);
MessageBox(NULL, teststr, "PMS Error Message", MB_OK);
e->Delete();
openOK = FALSE;
//throw; // this statement will terminate program at once.
}
//MessageBox(NULL, "Leaving", "Test", MB_OK);
return openOK;
}
//-----------------------------------------------------------------------------
// Name: SearchRecord()
// Desc: Look for required record
//-----------------------------------------------------------------------------


static bool SearchRecord(HWND hWnd, CDatabase *db)
{
COperationRecordset rst(db);
BOOL found;

found = FALSE;
rst.Open(CRecordset::dynaset);
while (!rst.IsEOF())
{
if (rst.v_Login_User == g_strlogin)
if (rst.v_Login_Password == g_strpassword)
// Successful Login set a ture value
found = TRUE;
rst.MoveNext();

}
return found;

}
///////////////////////////////////
// This event has been defined when a Space key is push
// Then, this dialog is use for login process
// Mesage handler for DIALOG box.
///////////////////////////////////
LRESULT CALLBACK DIALOGA(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

CDatabase db;
BOOL done= FALSE;

switch (message)
{
case WM_INITDIALOG:

return TRUE;

case WM_COMMAND:
if(LOWORD(wParam) == IDOK)
{
// UNIT GetDlgItemText(HWMD hDlg,int nID,LPSTR lpstr,int nMax);
GetDlgItemText(hDlg,IDLOGIN,g_strlogin,80); // get login bar text
GetDlgItemText(hDlg,IDPASSWORD,g_strpassword,80); // get password bar text

MessageBox(hDlg,TEXT("Testing Login proccess "),
TEXT("PMS Exit") , MB_YESNO);
// Open database
OpenDataBase(&db);
done = SearchRecord(hDlg, &db);
db.Close();

if (done=TRUE)
{g_FrameDisplay=1;}// Change the frame
else if (done=FALSE)
{
MessageBox(hDlg, "Sorry, Your input value did not find.Please try again !",
TEXT("PMS Login Error") , MB_ICONERROR|MB_OK);
}
//End Dialog
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}

if ( LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

// =============COperationRecordset.cpp : implementation file============
//

//#include "stdafx.h"
#include "COperationRecordset.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COperationRecordset

IMPLEMENT_DYNAMIC(COperationRecordset, CRecordset)

COperationRecordset::COperationRecordset(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(COperationRecordset)
v_Login_User= _T("");
v_Login_Password= _T("");
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}


CString COperationRecordset::GetDefaultConnect()
{
return _T("ODBC;DSN=MS Access 97 Database");
}

// Table Name
CString COperationRecordset::GetDefaultSQL()
{
return _T("[Login]");
}

void COperationRecordset::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(COperationRecordset)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[User]"), v_Login_User);
RFX_Text(pFX, _T("[Password]"), v_Login_Password);

//}}AFX_FIELD_MAP
}

/////////////////////////////////////////////////////////////////////////////
// COperationRecordset diagnostics

#ifdef _DEBUG
void COperationRecordset::AssertValid() const
{
CRecordset::AssertValid();
}

void COperationRecordset::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG

// ================COperationRecordset.h : header file===================
//
#include <afxdb.h>
#include <afx.h>

/////////////////////////////////////////////////////////////////////////////
// COperationRecordset recordset

class COperationRecordset : public CRecordset
{
public:
COperationRecordset(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(COperationRecordset)

// Field/Param Data
//{{AFX_FIELD(COperationRecordset, CRecordset)
CString v_Login_User;
CString v_Login_Password;
//}}AFX_FIELD


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(COperationRecordset)
public:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL

// Implementation
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};


Regards,
Anson Tong
GeneralRe: database error Pin
David Crow29-Dec-03 8:27
David Crow29-Dec-03 8:27 
GeneralRe: database error Pin
ansontong29-Dec-03 9:18
ansontong29-Dec-03 9:18 
GeneralRe: database error Pin
David Crow30-Dec-03 2:46
David Crow30-Dec-03 2:46 
Generaldll build problem Pin
will138329-Dec-03 6:00
will138329-Dec-03 6:00 
GeneralRe: dll build problem Pin
Brian Shifrin29-Dec-03 7:19
Brian Shifrin29-Dec-03 7:19 
GeneralMAPI Help Please! Pin
LizardWiz29-Dec-03 5:45
LizardWiz29-Dec-03 5:45 
GeneralRe: MAPI Help Please! Pin
David Crow29-Dec-03 5:58
David Crow29-Dec-03 5:58 
GeneralRe: MAPI Help Please! Pin
LizardWiz29-Dec-03 11:12
LizardWiz29-Dec-03 11:12 
GeneralRe: MAPI Help Please! Pin
Shog929-Dec-03 9:39
sitebuilderShog929-Dec-03 9:39 
GeneralPassing one-dimensional arrays to functions Pin
pf729-Dec-03 4:32
pf729-Dec-03 4:32 
GeneralRe: Passing one-dimensional arrays to functions Pin
David Crow29-Dec-03 5:10
David Crow29-Dec-03 5:10 
GeneralRe: Passing one-dimensional arrays to functions Pin
pf729-Dec-03 9:50
pf729-Dec-03 9:50 
GeneralRe: Passing one-dimensional arrays to functions Pin
Nitron29-Dec-03 11:10
Nitron29-Dec-03 11:10 
GeneralInterrupt functions Pin
Joe_G29-Dec-03 3:09
Joe_G29-Dec-03 3:09 
GeneralRe: Interrupt functions Pin
David Crow29-Dec-03 3:46
David Crow29-Dec-03 3:46 
GeneralRe: Interrupt functions Pin
Gary R. Wheeler29-Dec-03 11:36
Gary R. Wheeler29-Dec-03 11:36 
QuestionHow to get the user group in win NT/2000/XP Pin
C-lviu29-Dec-03 2:45
C-lviu29-Dec-03 2:45 

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.