ADO API Problem.
-
Can someone help me with the below ADO API? I am a new programmer and am having problems programming a SQL Server connection. I have found various connection strings and continue to run into problems with the syntax. Thank you in advance. #include "stdafx.h" #include #include #import "C:\Program files\Common Files\System\Ado\msado15.dll" rename("EOF", "ADOEOF") //--------------------------------------------------------------------------------------------------------------------------------------------- std::string outputashex(unsigned long l) { char buffer[1024]; ::itoa(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;Server=.\SQLExpress;AttachDbFilename=c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WattsALoan.mdf;Database=WattsALoan;Trusted_Connection=Yes;") //------------------------------------------------------------------------------------------------------------------------------------------- //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); //-------------------------------------------------------------------------------------------------------------