1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
BOOL CTestADOMFCDlg::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);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//CString sProvider("Provider=MSDAORA;Data Source=PRSDEV;User ID=PRS;Password=PRS");
CString sProvider("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\dev\\vc\\ADOExemple\\ADOExemple.mdb;Persist Security Info=False");
// Définition d'un objet de type ADOConnect pour établir la connexion avec la DB
myConn = new ADOConnect();
// Connexion à la base de données
if (!myConn->Connect(sProvider)) {
cout << myConn->GetError() << endl; //Affichage de l'erreur en cas de problème
AfxMessageBox("Unable to create ADOConnect Object");
exit (0);
}
else
AfxMessageBox("Connected");
Populate();
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestADOMFCDlg::Populate()
{
CListBox *lbTable = (CListBox *)GetDlgItem (IDC_LIST2);
ADOSelect mySel; //Définitin d'un object ADOSelect pour exécuter une requête
//Ouverture du recordset
if (!mySel.Open(myConn->ADOConn, "select * from emp")){
cout << mySel.GetError() << endl; // Affichage de l'erreur
} else {
//Ouverture réussie
mySel.FetchInListCtrl(&m_ListCtrl);
mySel.MoveFirst();
mySel.FetchInComboBox(&m_Combo);
mySel.Close();
}
// Garnit un type CgzCombo
if (!mySel.Open(myConn->ADOConn, "select ename, empno from emp")){
cout << mySel.GetError() << endl; // Affichage de l'erreur
} else {
// Delete previous content
while (m_gzCombo.GetCount() > 0) {
m_gzCombo.DeleteString( 0 );
}
while (mySel.Fetch()) {
CString ename;
CString empno;
mySel.GetFieldVal(0, ename);
mySel.GetFieldVal(1, empno);
m_gzCombo.AddRow(ename, empno);
}
mySel.Close();
}
if (!mySel.Open(myConn->ADOConn, "select ename from emp")){
cout << mySel.GetError() << endl; // Affichage de l'erreur
} else {
//Ouverture réussie
//mySel.FetchInListBox(&m_List);
mySel.FetchInListBox(lbTable);
mySel.Close();
}
if (!mySel.Open(myConn->ADOConn, "select * from boitiers")){
cout << mySel.GetError() << endl; // Affichage de l'erreur
} else {
int iRec = 0;
CString sTemp;
iRec = 2;
m_FlexGrid.SetCols(mySel.GetColCount() + 1);
for (int iCol = 0; iCol < mySel.GetColCount(); iCol++) {
m_FlexGrid.SetRow(0);
m_FlexGrid.SetCol(iCol+1);
m_FlexGrid.SetText(mySel.GetFieldName(iCol));
}
while (mySel.Fetch()) {
CString sField;
m_FlexGrid.SetRows(iRec);
m_FlexGrid.SetRow(iRec-1);
m_FlexGrid.SetRow(m_FlexGrid.GetRow());
m_FlexGrid.SetCol(0);
sTemp.Format("%d", iRec-1);
m_FlexGrid.SetText(sTemp);
for (int iCol = 0; iCol < mySel.GetColCount(); iCol++) {
m_FlexGrid.SetCol(iCol + 1);
mySel.GetFieldVal(iCol, sField);
m_FlexGrid.SetText(sField);
}
iRec++;
}
mySel.Close();
}
UpdateData(false);
} |
Partager