Listed below is the original program almost debugged completely. It took much work to figure out the proper syntax for the connection though with help from people on this board as well as others on other boards, I was able to piece it together. I am now encountering one error. The error is listed below:
Thank you nadroj for the help.
------ Build started: Project: Trade OptimizerV15, Configuration: Debug Win32 ------
Compiling...
Trade OptimizerV15.cpp
c:\documents and settings\mcertini\my documents\visual studio 2008\projects\tradeoptimizerv6\trade optimizerv15\trade optimizerv15\trade optimizerv15.cpp(42) : error C2664: 'ADODB::Connection15::Open' : cannot convert parameter 4 from 'const char [25]' to 'long'
There is no context in which this conversion is possible
Build log was saved at "file://c:\Documents and Settings\mcertini\My Documents\Visual Studio 2008\Projects\TradeOptimizerV6\Trade OptimizerV15\Trade OptimizerV15\Debug\BuildLog.htm"
Trade OptimizerV15 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:
// Trade OptimizerV15.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#import "C:\\Program files\\Common Files\\System\\Ado\\msado15.dll" rename("EOF", "ADOEOF")
//---------------------------------------------------------------------------------------------------------------------------------------------
std::string outputashex(unsigned long l)
{
char buffer[1024];
_itoa_s(l, buffer, 16);
return buffer;
} ;
//---------------------------------------------------------------------------------------------------------------------------------------------
void main()
{
HRESULT hr;
CoInitialize(NULL);
try
{
ADODB::_ConnectionPtr connection;
hr = connection.CreateInstance(__uuidof(ADODB::Connection));
if (FAILED(hr))
{
throw _com_error(hr);
}
//--------------------------------------------------------------------------------------------------------------------------------------------
ADODB::_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
//--------------------------------------------------------------------------------------------------------------------------------------------
connection->CursorLocation = ADODB::adUseClient;
//--------------------------------------------------------------------------------------------------------------------------------------------
connection->Open("Provider=SQLOLEDB;","Data Source=PCD-LT-MCERTINI\\SQLEXPRESS;","Initial Catalog=WattsALoan.mdf;","Integrated Security=SSPI");
//--------------------------------------------------------------------------------------------------------------------------------------------
//L"", ADODB::adConnectUnspecified);
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("CREATE TABLE mytable (value NVARCHAR(255))",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("INSERT INTO mytable VALUES ('Hello')",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("INSERT INTO mytable VALUES ('Goodbye')",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
recordset->Open("SELECT * from Customers",
connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,
ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
while(!recordset->ADOEOF)
{
_variant_t var;
var = recordset->Fields->GetItem(L"value")->GetValue();
std::cout << static_cast<char *>(_bstr_t(var.bstrVal))
<< std::endl;
recordset->MoveNext();
};
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Close();
//recordset->Open("DROP TABLE mytable", connection.GetInterfacePtr(),
//ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,
//ADODB::adCmdText);
}
catch(_com_error &e)
{
std::cerr << ::outputashex(hr) << ":"
<< static_cast<char *>(e.Description());
}
catch(...)
{
std::cerr << "Unhandled Exception";
};
}