Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem in SearchPath Pin
Mukkie29-Jan-04 5:50
Mukkie29-Jan-04 5:50 
GeneralRe: Problem in SearchPath Pin
SiddharthAtw29-Jan-04 22:14
SiddharthAtw29-Jan-04 22:14 
QuestionHave an idea, what do you think? Pin
youngjedi23-Jan-04 14:11
youngjedi23-Jan-04 14:11 
AnswerRe: Have an idea, what do you think? Pin
l a u r e n23-Jan-04 14:27
l a u r e n23-Jan-04 14:27 
GeneralAccess - changing database password from an EXE Pin
Kayembi23-Jan-04 9:07
Kayembi23-Jan-04 9:07 
GeneralRe: Access - changing database password from an EXE Pin
David Crow23-Jan-04 9:44
David Crow23-Jan-04 9:44 
GeneralCListView Custom Drawing: drop target icon Pin
bitpusher23-Jan-04 7:49
bitpusher23-Jan-04 7:49 
GeneralProblem Vith ADO-FoxPro Pin
Srdjan Mladenovic23-Jan-04 7:40
Srdjan Mladenovic23-Jan-04 7:40 
My application works just fine with Access and SQL server2000,but when i use FoxPro as Data Source i can't AddNew,Update or Delete record.
I dont recive eny errors from database.
is my Connection string OK?
Code Example:
//////////////////////////////////////////
#define INITGUID

#import "C:\Program Files\Common Files\System\ADO\msado15.dll"\
rename_namespace("ADOCG")\
rename("EOF", "EndOfFile")
using namespace ADOCG;
#include <stdio.h>

#include "icrsint.h"
class CADORazmena : public CADORecordBinding
{
BEGIN_ADO_BINDING(CADORazmena)
ADO_VARIABLE_LENGTH_ENTRY2(1,adVarChar, m_ID,sizeof(m_ID),lIDStatus,TRUE)
ADO_VARIABLE_LENGTH_ENTRY2(2,adVarChar, m_Garderoba,sizeof(m_Garderoba),lGarderobaStatus, TRUE)
END_ADO_BINDING()

public:
CHAR m_ID[50];
ULONG lIDStatus;
CHAR m_Garderoba[50];
ULONG lGarderobaStatus;
////////////////////////////////////////////////////
Document class
////////////////////////////////////////////////////
BOOL CKucniBudget2004Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// IDBInitialize* pIDBInitialize = NULL;
m_strConection=_T("Provider=vfpoledb;Data Source=c:\\data\\simpoz.dbc;");


m_strCmd=_T("select * from Kupci");
m_pRs = NULL;
m_piAdoRecordBinding = NULL;
// Initialize the COM environment
::CoInitialize(NULL);
try
{
// Create the record set object
m_pRs.CreateInstance(__uuidof(Recordset));

// Open the record set object
m_pRs->Open((LPCTSTR)m_strCmd, (LPCTSTR)m_strConection,
adOpenDynamic, adLockOptimistic, adCmdUnknown);

// Get a pointer to the record binding interface
if (FAILED(m_pRs->QueryInterface(__uuidof(IADORecordBinding),
(LPVOID *)&m_piAdoRecordBinding)))
_com_issue_error(E_NOINTERFACE);
// Bind the record class to the record set
m_piAdoRecordBinding->BindToRecordset(&m_rsRecSet);

// Get a pointer to the view
POSITION pos = GetFirstViewPosition();
CKucniBudget2004View* pView = (CKucniBudget2004View*)GetNextView(pos);
if (pView)
// Sync the data set with the form
pView->RefreshBoundData();
}
// Any errors?
catch (_com_error &e)
{
// Display the error
GenerateError(e.Error(), e.Description());
}

return TRUE;


}

void CKucniBudget2004Doc::AddNew()
{
try
{
m_piAdoRecordBinding->Update(&m_rsRecSet);
if(m_pRs->Supports(adAddNew))
{

CreateBlankRecord();
m_piAdoRecordBinding->AddNew(&m_rsRecSet);

m_pRs->MoveLast();
}

}

catch (_com_error &e)
{
GenerateError(e.Error(),e.Description());
}
}

void CKucniBudget2004Doc::CreateBlankRecord()
{
CString strBlank=" ";
// COleDateTime dtBlank;

strcpy(m_rsRecSet.m_ID,(LPCTSTR)strBlank);
strcpy(m_rsRecSet.m_Garderoba,(LPCTSTR)strBlank);
}
void CKucniBudget2004Doc::Delete()
{
try
{
m_piAdoRecordBinding->Update(&m_rsRecSet);
if(m_pRs->Supports(adDelete))
{
if(AfxMessageBox("Jeste li Sigurni Da hocete da Obrisete tekuci Zapis?",MB_YESNO | MB_ICONQUESTION) == IDYES)
{
m_pRs->Delete(adAffectCurrent);


m_pRs->MovePrevious();
}
}
}

catch (_com_error &e)
{
GenerateError(e.Error(),e.Description());
}
}

void CKucniBudget2004Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
if (m_pRs)
m_pRs->Close();
// Do we have a valid pointer to the record binding?
if (m_piAdoRecordBinding)
// Release it
// m_piAdoRecordBinding->Release();
// Set the record set pointer to NULL
m_pRs = NULL;

// Shut down the COM environment
CoUninitialize();

CDocument::DeleteContents();
}
void CKucniBudget2004Doc::GenerateError(HRESULT hr, PWSTR pwszDescription)
{
CString strError;
strError.Format("Greska broj'%d (%x)'",hr,hr);
strError+= "\n\n";
strError+=pwszDescription;
AfxMessageBox(strError);
}

CADORazmena* CKucniBudget2004Doc::GetRecSet()
{
return &m_rsRecSet;
}
///////////////////////////////////////////////
ViewClass
/////////////////////////////////////////
void CKucniBudget2004View::OnZapisBrisanjezapisa()
{
// TODO: Add your command handler code here
UpdateBoundData();
GetDocument()->Delete();
RefreshBoundData();
}
void CKucniBudget2004View::OnZapisNovizapis()
{
// TODO: Add your command handler code here


UpdateBoundData();

GetDocument()->AddNew();

RefreshBoundData();

UpdateData(FALSE);

}
void CKucniBudget2004View::RefreshBoundData()
{
CADORazmena* pRs;
pRs = GetDocument()->GetRecSet();

// Is the field OK
if (adFldOK == pRs->lIDStatus)
m_ID = pRs->m_ID;
else
m_ID = _T(" ");
if (adFldOK == pRs->lGarderobaStatus)
m_Garderoba = pRs->m_Garderoba;
else
m_Garderoba = _T(" ");
UpdateData(FALSE);
}

void CKucniBudget2004View::UpdateBoundData()
{
CADORazmena* pRs;
pRs=GetDocument()->GetRecSet();
UpdateData(TRUE);
if(m_ID != pRs->m_ID)
{
strcpy(pRs->m_ID,(LPCTSTR)m_ID);
}
if(m_Garderoba != pRs->m_Garderoba)
{
strcpy(pRs->m_Garderoba,(LPCTSTR)m_Garderoba);
}
////////////////////////////////////////////////

Generalnewbie having error LNK2005 problem Pin
skletty23-Jan-04 7:23
skletty23-Jan-04 7:23 
GeneralRe: newbie having error LNK2005 problem Pin
David Crow23-Jan-04 9:49
David Crow23-Jan-04 9:49 
GeneralRe: newbie having error LNK2005 problem Pin
skletty23-Jan-04 10:06
skletty23-Jan-04 10:06 
GeneralRe: newbie having error LNK2005 problem Pin
David Crow23-Jan-04 10:17
David Crow23-Jan-04 10:17 
GeneralRe: newbie having error LNK2005 problem Pin
skletty23-Jan-04 10:20
skletty23-Jan-04 10:20 
GeneralRe: newbie having error LNK2005 problem Pin
Jörgen Sigvardsson24-Jan-04 6:12
Jörgen Sigvardsson24-Jan-04 6:12 
GeneralRe: newbie having error LNK2005 problem Pin
Michael Dunn23-Jan-04 12:46
sitebuilderMichael Dunn23-Jan-04 12:46 
GeneralDialog from CHTMLView Pin
Frank Deo23-Jan-04 6:50
Frank Deo23-Jan-04 6:50 
GeneralServer 2003 DDK, ZMODEM Pin
Shahin7723-Jan-04 6:41
Shahin7723-Jan-04 6:41 
GeneralRe: Server 2003 DDK, ZMODEM Pin
Alexander M.,24-Jan-04 7:49
Alexander M.,24-Jan-04 7:49 
GeneralRe: Server 2003 DDK, ZMODEM Pin
Shahin7724-Jan-04 8:30
Shahin7724-Jan-04 8:30 
GeneralMFC main thread return codes Pin
Dominik Reichl23-Jan-04 6:23
Dominik Reichl23-Jan-04 6:23 
GeneralRe: MFC main thread return codes Pin
Michael Dunn23-Jan-04 6:27
sitebuilderMichael Dunn23-Jan-04 6:27 
GeneralRe: MFC main thread return codes Pin
J. Eric Vaughan23-Jan-04 8:54
J. Eric Vaughan23-Jan-04 8:54 
GeneralRe: MFC main thread return codes Pin
Antti Keskinen23-Jan-04 22:49
Antti Keskinen23-Jan-04 22:49 
GeneralSQL and Windows Database Programming Pin
valikac23-Jan-04 6:11
valikac23-Jan-04 6:11 
GeneralRe: SQL and Windows Database Programming Pin
Michael P Butler23-Jan-04 7:05
Michael P Butler23-Jan-04 7:05 

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.