I have an openGL window within an MFC dialog. I've connected to MSAccess as my DB where i pick coordinates which i use to draw GL_LINES and GL_QUADS.

I've checked out my code and it seems to be working correctly but nothing shows on the GLWindow. Wne i hardcode values ... it shows sometimes and other times it doesn't. Might anyone know what i'm doing wrong here?

Any help would be highly appreciated...

My code for connecting and drawing is as follows:
Code:
/**************DATABASE CONNECTION*************/
/*	*/
	HRESULT hr;
	CoInitialize(NULL);
	
	try{
		//Create a pointer to a Connection in memory
		//ADODB::_ConnectionPtr cnSURMPtr;
		hr = cnSURMPtr2.CreateInstance(__uuidof(ADODB::Connection));
		if (FAILED(hr))
		{
			throw _com_error(hr);
		}
		
		//Create a pointer to a Recordset in memory
		hr = rsObjectsPtr.CreateInstance(__uuidof(ADODB::Recordset));
		if (FAILED(hr))
		{
			throw _com_error(hr);
		}
		
		//Set Connection properties
		cnSURMPtr2->CursorLocation = ADODB::adUseClient;
		
		//Generate connection string
		_bstr_t dbLocation(L"");
		dbLocation = (L".\\SURM.mdb");
		
		//Open the connection
		cnSURMPtr2->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ dbLocation +";Persist Security Info=False","","",ADODB::adConnectUnspecified);

		//Open Objects recordset
		rsObjectsPtr->Open("SELECT * from Objects", cnSURMPtr2.GetInterfacePtr(),
		ADODB::adOpenDynamic, ADODB::adLockOptimistic, ADODB::adCmdText);
		
		//Read from First to Last Record to load into GLWindow
		if(!rsObjectsPtr->ADOEOF){
			if(rsObjectsPtr->GetRecordCount()>0){
				//Move to the FIRST record
				//rsObjectsPtr->MoveFirst();
				while (rsObjectsPtr->ADOEOF == false){
					//Code to load cordinates in GLWindow
					_variant_t myCoordinates;
					
					//Read from DB
					myCoordinates = rsObjectsPtr->GetCollect(L"Coordinates");
					//myCoordinates = rsObjectsPtr->Fields->GetItem(L"Coordinates")->GetValue();

					if(myCoordinates.vt != VT_NULL){
						//Change to String and pick each vertex coordinate
						CString myStrCoords;

						myStrCoords = static_cast<char *>(_bstr_t(myCoordinates.bstrVal));
						
						//if(myStrCoords != ""){
						//Determine array size
						int myArraySize = (myStrCoords.GetLength()/9);
						//CString singleCoord[myArraySize] = new CString[myArraySize];
						CString *singleCoord = new CString[myArraySize];
						int tokenCounter = 0;
						
						//Put each token into an array element 
						while(myStrCoords.GetLength()>=9){
							singleCoord[tokenCounter] = myStrCoords.Left(9);
							//myStrCoords.TrimLeft(10);
							myStrCoords.Delete(0,10);
							tokenCounter++;
						}
						
						//Draw the LINES or QUADS
						if(tokenCounter<=2){
							//openGLControl.drawLine((string)singleCoord[0],(string)singleCoord[0]);
							//glBegin(GL_LINES);
							drawLine((string)singleCoord[0],(string)singleCoord[0]);
							//drawLine("000000000","000000005");
						}
						else{
							//glBegin(GL_QUADS);
							//openGLControl.drawQuad((string)singleCoord[0],(string)singleCoord[1],(string)singleCoord[2],(string)singleCoord[3]);
							drawQuad((string)singleCoord[0],(string)singleCoord[1],(string)singleCoord[2],(string)singleCoord[3]);
							drawQuad("000001000","000001001","000000001","000000000");
							//drawLine("000000000","000000005");
						}
					}//IF statement end bracket
					//Move to next record if not EOF
					rsObjectsPtr->MoveNext();
				}
				if(rsObjectsPtr->BOF){
					rsObjectsPtr->MoveFirst();
				}
				if(rsObjectsPtr->ADOEOF){
					rsObjectsPtr->MoveLast();
				}
			};
		}
	}
	catch(_com_error &e)
	{

		AfxMessageBox(static_cast<char *>(e.Description()));
		//ShowWindow(1);
	}
	catch(...)
	{
		//std::cerr << "Unhandled Exception";
		AfxMessageBox("Unhandled Exception");
	};
	
/**/
   //This hard-coded part works only at this point in the code
   drawQuad("000001000","000001001","000000001","000000000");

   SwapBuffers(dc->m_hDC);
}
This is the code for drawing the QUAD
Code:
void COpenGLControl::drawQuad(string Coord_A, string Coord_B, string Coord_C, string Coord_D){
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glLoadIdentity();
	
	//Split Coord_A,B,C,D into x,y,z
/**/
	//Split Coord_A into x,y,z
	//Convert to CString before casting
	float myAx = atof(Coord_A.substr(0,3).c_str());
	float Ax = (myAx/10);
	float myAy = atof(Coord_A.substr(3,3).c_str());
	float Ay = (myAy/10);
	float myAz = atof(Coord_A.substr(6,3).c_str());
	float Az = (myAz/10);

	//Split Coord_B into x,y,z
	//Convert to CString before casting
	float myBx = atof(Coord_B.substr(0,3).c_str());
	float Bx = (myBx/10);
	float myBy = atof(Coord_B.substr(3,3).c_str());
	float By = (myBy/10);
	float myBz = atof(Coord_B.substr(6,3).c_str());
	float Bz = (myBz/10);
	
	//Split Coord_C into x,y,z
	//Convert to CString before casting
	float myCx = atof(Coord_C.substr(0,3).c_str());
	float Cx = (myCx/10);
	float myCy = atof(Coord_C.substr(3,3).c_str());
	float Cy = (myCy/10);
	float myCz = atof(Coord_C.substr(6,3).c_str());
	float Cz = (myCz/10);

	//Split Coord_D into x,y,z
	//Convert to CString before casting
	float myDx = atof(Coord_D.substr(0,3).c_str());
	float Dx = (myDx/10);
	float myDy = atof(Coord_D.substr(3,3).c_str());
	float Dy = (myDy/10);
	float myDz = atof(Coord_D.substr(6,3).c_str());
	float Dz = (myDz/10);
/**/
	glBegin(GL_QUADS);
		glColor3f(0.0,1.0,0.0);
/**/		
		glVertex3f(Ax,Ay,Az);
		glVertex3f(Bx,By,Bz);
		glVertex3f(Cx,Cy,Cz);
		glVertex3f(Dx,Dy,Dz);
	glEnd();
}