Click here to Skip to main content
15,909,822 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: FTP download status call back problem Pin
Rajesh R Subramanian19-Apr-11 20:25
professionalRajesh R Subramanian19-Apr-11 20:25 
QuestionBasic array problem Pin
VCProgrammer19-Apr-11 19:28
VCProgrammer19-Apr-11 19:28 
AnswerRe: Basic array problem Pin
Cool_Dev19-Apr-11 19:51
Cool_Dev19-Apr-11 19:51 
AnswerRe: Basic array problem Pin
Rajesh R Subramanian19-Apr-11 20:16
professionalRajesh R Subramanian19-Apr-11 20:16 
GeneralRe: Basic array problem Pin
VCProgrammer19-Apr-11 20:57
VCProgrammer19-Apr-11 20:57 
GeneralRe: Basic array problem Pin
Cool_Dev19-Apr-11 21:24
Cool_Dev19-Apr-11 21:24 
AnswerRe: Basic array problem Pin
Niklas L19-Apr-11 22:15
Niklas L19-Apr-11 22:15 
Questioni having problem to connect my MFC form to Access database using sql query.. Pin
tohard19-Apr-11 14:51
tohard19-Apr-11 14:51 
this is my code.. it's not work properly.. i have downloaded this code from internet.. when i edit at file that i have downloaded.. i work properly.. but when i create a new form.. it's not work.. can anyone help me?

#include "stdafx.h"
#include "trans.h"
#include "transDlg.h"
#include "afxdb.h"
#include "odbcinst.h"

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


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CtransDlg dialog




CtransDlg::CtransDlg(CWnd* pParent /*=NULL*/)
: CDialog(CtransDlg::IDD, pParent)
, drv(_T(""))
, pm(_T(""))
, cs1(_T(""))
, cs2(_T(""))
, cs3(_T(""))
, cs4(_T(""))
, cs5(_T(""))
, cs6(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CtransDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, drv);
DDX_Text(pDX, IDC_EDIT2, pm);
DDX_Text(pDX, IDC_EDIT3, cs1);
DDX_Text(pDX, IDC_EDIT4, cs2);
DDX_Text(pDX, IDC_EDIT5, cs3);
DDX_Text(pDX, IDC_EDIT6, cs4);
DDX_Text(pDX, IDC_EDIT7, cs5);
DDX_Text(pDX, IDC_EDIT8, cs6);
}

BEGIN_MESSAGE_MAP(CtransDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CtransDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, &CtransDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CtransDlg::OnBnClickedButton2)
END_MESSAGE_MAP()


// CtransDlg message handlers

BOOL CtransDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CtransDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CtransDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CtransDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}


void CtransDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
OnOK();
}

CString S, sp1, sp2, sp3, sp4, sp5, sp6;
void CtransDlg::OnBnClickedButton1()
{
CDatabase database;
CString SqlString;
CString sItem1, sItem2, sItem3, sItem4, sItem5, sItem6, sItem7, sItem8;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "H:\\project\\excel_odbc_demo\\book1.mdb";
// You must change above path if it's different
int iRec = 0;

UpdateData(true);
pm;

// Build ODBC connection string
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);

TRY
{
// Open the database
database.Open(NULL,false,false,sDsn);

// Allocate the recordset
CRecordset recset( &database );

// Build the SQL statement
SqlString = "SELECT field_1, field_2, field_3, field_4, field_5, field_6, field_7, field_8 "
"FROM WorkSheet "
"ORDER BY field_1";

// Execute the query
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);

// Loop through each record
while( !recset.IsEOF() )
{
// Copy each column into a variable
recset.GetFieldValue("field_1",sItem1);
recset.GetFieldValue("field_2",sItem2);
recset.GetFieldValue("field_3",sItem3);
recset.GetFieldValue("field_4",sItem4);
recset.GetFieldValue("field_5",sItem5);
recset.GetFieldValue("field_6",sItem6);
recset.GetFieldValue("field_7",sItem7);
recset.GetFieldValue("field_8",sItem8);

if(sItem1 == pm)
{

S = sItem2;
sp1 = sItem3;
sp2 = sItem4;
sp3 = sItem5;
sp4 = sItem6;
sp5 = sItem7;
sp6 = sItem8;

}

// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, show error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;

drv = S;
UpdateData(false);
}

void CtransDlg::OnBnClickedButton2()
{
UpdateData(true);
pm = S;
cs1 = sp1;
cs2 = sp2;
cs3 = sp3;
cs4 = sp4;
cs5 = sp5;
cs6 = sp6;
UpdateData(false);
}

the error is.. :-
Error 1 error C2440: 'initializing' : cannot convert from 'const char [32]' to 'ATL::CStringT<BaseType,StringTraits>' h:\trans\trans\transdlg.cpp 187 trans
Error 2 error C2440: 'initializing' : cannot convert from 'const char [37]' to 'ATL::CStringT<BaseType,StringTraits>' h:\trans\trans\transdlg.cpp 189 trans
Error 3 error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [31]' to 'const wchar_t *' h:\trans\trans\transdlg.cpp 197 trans
Error 4 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 219 trans
Error 5 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 220 trans
Error 6 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 221 trans
Error 7 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 222 trans
Error 8 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 223 trans
Error 9 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 224 trans
Error 10 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 225 trans
Error 11 error C2664: 'void CRecordset::GetFieldValue(LPCTSTR,CDBVariant &,short)' : cannot convert parameter 1 from 'const char [8]' to 'LPCTSTR' h:\trans\trans\transdlg.cpp 226 trans
Error 12 error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const char [17]' (or there is no acceptable conversion) h:\trans\trans\transdlg.cpp 250 trans
AnswerRe: i having problem to connect my MFC form to Access database using sql query.. Pin
Rajesh R Subramanian19-Apr-11 20:23
professionalRajesh R Subramanian19-Apr-11 20:23 
QuestionShared Library o DLL? Pin
Andy20219-Apr-11 6:36
Andy20219-Apr-11 6:36 
AnswerRe: Shared Library o DLL? Pin
Albert Holguin19-Apr-11 7:30
professionalAlbert Holguin19-Apr-11 7:30 
QuestionDeskband (XP) Problem.. Pin
nitin319-Apr-11 5:54
nitin319-Apr-11 5:54 
QuestionProblems with getting data from a Edit Control [modified] Pin
jhoesche19-Apr-11 4:54
jhoesche19-Apr-11 4:54 
AnswerRe: Problems with getting data from a Edit Control Pin
David Crow19-Apr-11 7:13
David Crow19-Apr-11 7:13 
GeneralRe: Problems with getting data from a Edit Control Pin
jhoesche19-Apr-11 8:49
jhoesche19-Apr-11 8:49 
AnswerRe: Problems with getting data from a Edit Control Pin
Hans Dietrich19-Apr-11 11:37
mentorHans Dietrich19-Apr-11 11:37 
GeneralRe: Problems with getting data from a Edit Control Pin
jhoesche19-Apr-11 12:12
jhoesche19-Apr-11 12:12 
GeneralRe: Problems with getting data from a Edit Control [modified] Pin
David Crow20-Apr-11 3:47
David Crow20-Apr-11 3:47 
GeneralRe: Problems with getting data from a Edit Control Pin
jhoesche20-Apr-11 5:56
jhoesche20-Apr-11 5:56 
GeneralRe: Problems with getting data from a Edit Control Pin
David Crow20-Apr-11 6:54
David Crow20-Apr-11 6:54 
GeneralRe: Problems with getting data from a Edit Control Pin
jhoesche20-Apr-11 7:16
jhoesche20-Apr-11 7:16 
GeneralRe: Problems with getting data from a Edit Control Pin
David Crow20-Apr-11 7:26
David Crow20-Apr-11 7:26 
GeneralRe: Problems with getting data from a Edit Control Pin
jhoesche20-Apr-11 10:12
jhoesche20-Apr-11 10:12 
GeneralRe: Problems with getting data from a Edit Control Pin
David Crow20-Apr-11 10:41
David Crow20-Apr-11 10:41 
Questionhow to initialize a variable whose name is passed as a string with a given value in a function in vc++6.0 Pin
manoharbalu19-Apr-11 2:36
manoharbalu19-Apr-11 2:36 

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.