www.pudn.com > TestMyADO.zip > Main.cpp, change:2003-07-27,size:3599b


// Copyright 2003 Nathan Davies 
// 
////////////////////////////////////////////////////////////////////// 
 
#include  
 
#include "MyADO.h" 
 
void main() 
{ 
	// Initialize COM 
	CoInitialize( NULL ); 
 
	// Instantiate the Object 
	CMyADO MyADOObject; 
 
	// Open( ConnectionString, UserID, Password ) the Connection 
	if( MyADOObject.Open( "TestMyADO", "", "" ) == S_OK ) 
	{ 
		// Some Example Strings 
		char* pNames[] = { "First Name", "Second Name", "Third Name", "Fourth Name", "Fifth Name", "Sixth Name", "Seventh Name", "Eighth Name", "Nineth Name", "Tenth Name" }; 
		char* pValues[] = { "Value One", "Value Two", "Value Three", "Value Four", "Value Five", "Value Six", "Value Seven", "Value Eight", "Value Nine", "Value Ten" }; 
 
		// The Index 
		DWORD dwIndex = 0; 
 
		// The Insert Loop 
		while( dwIndex < 10 ) 
		{ 
			// Initialize( StoredProcedureName ) the Stored Procedure 
			if( MyADOObject.Initialize( "InsertMyADO" ) == S_OK ) 
			{ 
				// Add the Return Value Parameter 
				if( MyADOObject.AddParameterReturnValue() == S_OK ) 
				{ 
					// Add the Output Long Parameter 
					if( MyADOObject.AddParameterOutputLong( "ID" ) == S_OK ) 
					{ 
						// Add the Input Text Parameters 
						if( MyADOObject.AddParameterInputText( "Name", pNames[dwIndex] ) == S_OK && 
							MyADOObject.AddParameterInputText( "Value", pValues[dwIndex] ) == S_OK ) 
						{ 
							// Execute the Stored Procedure 
							if( MyADOObject.Execute() == S_OK ) 
							{ 
								long lReturnValue = 0; 
								long lID = 0; 
 
								// Retrieve the Return Value and the Output Paramter set up above 
								if( MyADOObject.GetParameterReturnValue( &lReturnValue ) == S_OK && 
									MyADOObject.GetParameterLong( "ID", &lID ) == S_OK ) 
								{ 
									// Sanity check that does nothing : ) 
									if( lReturnValue == lID ) 
										printf( "Inserted Record with ID: %2d, Name: %15s, Value: %15s\n", lID, pNames[dwIndex], pValues[dwIndex] ); 
								} 
								else 
									printf( "ERR: Unable to Retrieve Return Value And ID\n" ); 
							} 
							else 
								printf( "ERR: Unable to Execute InsertMyADO\n" ); 
						} 
						else 
							printf( "ERR: Unable to Add the Input Text Values\n" ); 
					} 
					else 
						printf( "ERR: Unable to Add the Output Long Value\n" ); 
				} 
				else 
					printf( "ERR: Unable to Add the Return Value\n" ); 
			} 
			else 
				printf( "ERR: Unable to Initialize InsertMyADO\n" ); 
 
			// Increment the Index 
			dwIndex++; 
		} 
 
		// Initialize( StoredProcedureName ) the Stored Procedure 
		if( MyADOObject.Initialize( "SelectMyADO" ) == S_OK ) 
		{ 
			// Execute the Stored Procedure 
			if( MyADOObject.Execute() == S_OK ) 
			{ 
				// Ensure there are more Records to Retrieve 
				while( !MyADOObject.IsEOF()) 
				{ 
					long lID = 0; 
					char szName[15]; 
					char szValue[15]; 
 
					// Retrieve the Record Fields 
					if( MyADOObject.GetFieldLong( "ID", &lID ) == S_OK && 
						MyADOObject.GetFieldText( "Name", szName, sizeof( szName )) == S_OK && 
						MyADOObject.GetFieldText( "Value", szValue, sizeof( szValue )) == S_OK ) 
						printf( "Selected Record with ID: %2d, Name: %15s, Value: %15s\n", lID, szName, szValue ); 
 
					// Move to the Next Record 
					MyADOObject.MoveNext(); 
				} 
			} 
			else 
				printf( "ERR: Unable to Execute SelectMyADO\n" ); 
		} 
		else 
			printf( "ERR: Unable to Initialize SelectMyADO\n" ); 
 
		// Close the Connection 
		MyADOObject.Close(); 
	} 
 
	// For every action there must be an opposite and equal reaction 
	CoUninitialize(); 
}