Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. VC++ and MS SQL Server 2005 database

VC++ and MS SQL Server 2005 database

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasesql-serversysadminalgorithms
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    phokojoe
    wrote on last edited by
    #1

    I have been searching the net for a simple database application using visual c++. I want somebody to help me with how to develop just a small application for entering records, deleting, updating and searching using visual c++ and ms sql server 2005. Even if it can be for one record, I can extend that to whatever the number of columns I have in my database. I have been developing some but all in vain. Nothing seems to work. Please!:((

    phokojoe

    M D 2 Replies Last reply
    0
    • P phokojoe

      I have been searching the net for a simple database application using visual c++. I want somebody to help me with how to develop just a small application for entering records, deleting, updating and searching using visual c++ and ms sql server 2005. Even if it can be for one record, I can extend that to whatever the number of columns I have in my database. I have been developing some but all in vain. Nothing seems to work. Please!:((

      phokojoe

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      phokojoe wrote:

      Nothing seems to work

      What have you tried that didn't work? Is the problem UI related? Database access related?

      phokojoe wrote:

      how to develop just a small application for entering records, deleting, updating and searching

      Maybe break that down into managable chunks and show some sample code that you're having trouble with and we can hopefully help you out. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      1 Reply Last reply
      0
      • P phokojoe

        I have been searching the net for a simple database application using visual c++. I want somebody to help me with how to develop just a small application for entering records, deleting, updating and searching using visual c++ and ms sql server 2005. Even if it can be for one record, I can extend that to whatever the number of columns I have in my database. I have been developing some but all in vain. Nothing seems to work. Please!:((

        phokojoe

        D Offline
        D Offline
        Dustin Henry
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups