Click here to Skip to main content
15,910,878 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Read char with X/Y axes? Pin
Lord Kixdemp8-Feb-06 10:55
Lord Kixdemp8-Feb-06 10:55 
QuestionApplication hangs when interrupted Pin
Joel McAlduff5-Feb-06 5:46
Joel McAlduff5-Feb-06 5:46 
AnswerMessage Closed Pin
5-Feb-06 8:44
ddmcr5-Feb-06 8:44 
GeneralRe: Application hangs when interrupted Pin
Joel McAlduff5-Feb-06 8:56
Joel McAlduff5-Feb-06 8:56 
QuestionRetrieving data from an ODBC data source Pin
SWDevil5-Feb-06 4:26
SWDevil5-Feb-06 4:26 
AnswerRe: Retrieving data from an ODBC data source Pin
Joel McAlduff5-Feb-06 4:44
Joel McAlduff5-Feb-06 4:44 
GeneralRe: Retrieving data from an ODBC data source Pin
SWDevil5-Feb-06 4:52
SWDevil5-Feb-06 4:52 
GeneralRe: Retrieving data from an ODBC data source Pin
Joel McAlduff5-Feb-06 5:22
Joel McAlduff5-Feb-06 5:22 
Here is a simple example. I left out A LOT of defensive coding to keep it short. Usually I am connecting to a single database within SQL server or Oracle, so I like to do this once and keep the connection open for the duration the application is active. Thus, I use a pointer to the database object and allocate memory for this with the new command (followed by a delete command later). I am usually in and out of recordsets so I tend to just create these objects within the functions that use them.



// Create and Open the Database via ODBC
CString strDSN = "DSN=The_DomainServiceName_Here; UID=User_ID_Here; PWD=Password_Here";
CDatabase* m_pDB;
m_pDB = new CDatabase;
m_pDB->OpenEx(strDSN,CDatabase::openReadOnly);


// Create and Open a Recordset connected to the database above
CString str, strMessage;
CRecordset rs(m_pDB);
str = "SELECT SOME_FIELDS FROM SOME_TABLES WHERE BLAH BLAH... ";
rs.Open(AFX_DB_USE_DEFAULT_TYPE,str,CRecordset::none);

while (!rs.IsEOF())
{
rs.GetFieldValue("FIELD_NAME1",str);
strMessage += str;
rs.GetFieldValue("FIELD_NAME2",str);
strMessage += " ";
strMessage += str;
rs.MoveNext();
}

AfxMessageBox(strMessage);

rs.Close();

m_pDB->Close();
delete m_pDB;
m_pDB = NULL;


Hope this helps.
GeneralRe: Retrieving data from an ODBC data source Pin
SWDevil5-Feb-06 20:55
SWDevil5-Feb-06 20:55 
AnswerRe: Retrieving data from an ODBC data source Pin
David Crow7-Feb-06 2:54
David Crow7-Feb-06 2:54 
GeneralRe: Retrieving data from an ODBC data source Pin
SWDevil7-Feb-06 5:25
SWDevil7-Feb-06 5:25 
GeneralRe: Retrieving data from an ODBC data source Pin
David Crow7-Feb-06 5:34
David Crow7-Feb-06 5:34 
QuestionVisual Studio 2005 Standard - MFC? Pin
Dominik Reichl5-Feb-06 2:08
Dominik Reichl5-Feb-06 2:08 
AnswerRe: Visual Studio 2005 Standard - MFC? Pin
Jack Puppy5-Feb-06 3:21
Jack Puppy5-Feb-06 3:21 
QuestionDetecting flash animation and pop-ups Pin
llp00na5-Feb-06 2:01
llp00na5-Feb-06 2:01 
QuestionRotation text Pin
duvaft4-Feb-06 23:08
duvaft4-Feb-06 23:08 
AnswerRe: Rotation text Pin
Eugene Pustovoyt5-Feb-06 0:21
Eugene Pustovoyt5-Feb-06 0:21 
AnswerRe: Rotation text Pin
EXTEIDE5-Feb-06 1:23
EXTEIDE5-Feb-06 1:23 
GeneralRe: Rotation text Pin
Eugene Pustovoyt5-Feb-06 2:14
Eugene Pustovoyt5-Feb-06 2:14 
GeneralRe: Rotation text Pin
EXTEIDE5-Feb-06 3:41
EXTEIDE5-Feb-06 3:41 
AnswerRe: Rotation text Pin
Stephen Hewitt5-Feb-06 20:13
Stephen Hewitt5-Feb-06 20:13 
QuestionHow to go about porting to windows? Pin
Chintoo7234-Feb-06 22:42
Chintoo7234-Feb-06 22:42 
QuestionHow can I get a PropertyPage title without or before creating? Pin
Eugene Pustovoyt4-Feb-06 20:36
Eugene Pustovoyt4-Feb-06 20:36 
AnswerRe: How can I get a PropertyPage title without or before creating? Pin
PJ Arends5-Feb-06 9:55
professionalPJ Arends5-Feb-06 9:55 
GeneralRe: How can I get a PropertyPage title without or before creating? Pin
Eugene Pustovoyt5-Feb-06 19:19
Eugene Pustovoyt5-Feb-06 19:19 

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.