Click here to Skip to main content
15,915,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to work with the registry from a limited account in windows xp Pin
skornel15-May-07 10:18
skornel15-May-07 10:18 
QuestionRe: How to work with the registry from a limited account in windows xp Pin
David Crow15-May-07 17:12
David Crow15-May-07 17:12 
AnswerRe: How to work with the registry from a limited account in windows xp [modified] Pin
OmurOlmez13-May-09 20:34
OmurOlmez13-May-09 20:34 
GeneralRe: How to work with the registry from a limited account in windows xp Pin
David Crow14-May-09 2:30
David Crow14-May-09 2:30 
QuestionWSASend notification with IOCP Pin
shizam115-May-07 5:18
shizam115-May-07 5:18 
QuestionVC++ and MS SQL Server 2005 database Pin
phokojoe15-May-07 5:04
phokojoe15-May-07 5:04 
AnswerRe: VC++ and MS SQL Server 2005 database Pin
Mark Salsbery15-May-07 6:02
Mark Salsbery15-May-07 6:02 
AnswerRe: VC++ and MS SQL Server 2005 database Pin
Dustin Henry15-May-07 6:05
Dustin Henry15-May-07 6:05 
You need to look into using the CDatabase[^] class. Below is come code to read some records from an Access DB which can be easily modified for MS SQL Server. Using those two classes you can update, read, create, etc. I believe I got much of this original code from CP but I cannot for the life of me remember where so I can't credit the author.
CDatabase	  m_database;	// Our database
CRecordset	*m_recset;	// Pointer to a record

bool Read()
{
	
	CString SqlString;
	CString sVideoName, sFileLocationRelative;
	CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
	CString sDsn;
	CString sFile = "Database\\VideoDB2.mdb";
	// You must change above path if it's different
	
	// Build ODBC connection CString
	sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
	TRY
	{
		// Open the database
		m_database.Open(NULL,false,false,sDsn);
		
		// Allocate the recordset
		m_recset = new CRecordset( &m_database );

		SqlString =  "SELECT * FROM VIDEOS";
		// Execute the query
		m_recset->Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
		// Loop through each record
		while( !m_recset->IsEOF() )
		{
			VideoRecord	tVideo;
			CDBVariant vID;
			CDBVariant vRunTime;
			CDBVariant vName;
			CDBVariant vImagePath;
			CDBVariant vVideoPath;
			CDBVariant vDescription;
			// Copy each column into a variable
			m_recset->GetFieldValue("VIDEO_ID",			vID);
			m_recset->GetFieldValue("VIDEO_RUN_TIME",	vRunTime);
			m_recset->GetFieldValue("VIDEO_NAME",		vName);
			m_recset->GetFieldValue("VIDEO_IMAGE_PATH",vImagePath);
			m_recset->GetFieldValue("VIDEO_PATH",		vVideoPath);
			m_recset->GetFieldValue("VIDEO_DESCRIPTION",vDescription);

			tVideo.iVideoID			= vID.m_iVal;
			tVideo.lRunTime			= vRunTime.m_lVal;
			tVideo.stVideoName		= *vName.m_pstring;
			tVideo.stImagePath		= *vImagePath.m_pstring;
			tVideo.stVideoPath		= *vVideoPath.m_pstring;
			tVideo.stDescription	= *vDescription.m_pstring;

			m_vVideos.push_back(tVideo);
			// goto next record
			m_recset->MoveNext();
		}
		m_recset->Close();
	}
	CATCH(CDBException, e)
	{
		// If a database exception occured, show error msg
		AfxMessageBox("Database error: "+e->m_strError);
		return false;
	}
	END_CATCH;
	return true;
}

By the way, that VideoRecord structure was just a part of my program, so you can ignore it.

Hope this is helpful,
Dustin
QuestionKeep CScrollView scrollbars visible Pin
bob1697215-May-07 4:00
bob1697215-May-07 4:00 
AnswerRe: Keep CScrollView scrollbars visible Pin
Hans Dietrich15-May-07 4:43
mentorHans Dietrich15-May-07 4:43 
GeneralRe: Keep CScrollView scrollbars visible Pin
bob1697215-May-07 5:02
bob1697215-May-07 5:02 
AnswerRe: Keep CScrollView scrollbars visible Pin
Mark Salsbery15-May-07 4:45
Mark Salsbery15-May-07 4:45 
GeneralRe: Keep CScrollView scrollbars visible Pin
bob1697215-May-07 4:51
bob1697215-May-07 4:51 
QuestionDialog Based application Pin
Kiran Pinjala15-May-07 3:56
Kiran Pinjala15-May-07 3:56 
AnswerRe: Dialog Based application Pin
Hans Dietrich15-May-07 4:14
mentorHans Dietrich15-May-07 4:14 
GeneralRe: Dialog Based application Pin
Kiran Pinjala15-May-07 4:19
Kiran Pinjala15-May-07 4:19 
AnswerRe: Dialog Based application Pin
Nelek15-May-07 21:39
protectorNelek15-May-07 21:39 
Questionget value(address) from ipaddress control Pin
prathuraj15-May-07 3:54
prathuraj15-May-07 3:54 
QuestionRe: get value(address) from ipaddress control Pin
David Crow15-May-07 4:03
David Crow15-May-07 4:03 
AnswerRe: get value(address) from ipaddress control Pin
prathuraj15-May-07 4:20
prathuraj15-May-07 4:20 
QuestionRe: get value(address) from ipaddress control Pin
David Crow15-May-07 4:33
David Crow15-May-07 4:33 
AnswerRe: get value(address) from ipaddress control Pin
prathuraj15-May-07 5:27
prathuraj15-May-07 5:27 
QuestionRe: get value(address) from ipaddress control Pin
David Crow15-May-07 6:00
David Crow15-May-07 6:00 
AnswerRe: get value(address) from ipaddress control Pin
prathuraj15-May-07 6:09
prathuraj15-May-07 6:09 
GeneralRe: get value(address) from ipaddress control Pin
David Crow15-May-07 6:28
David Crow15-May-07 6:28 

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.