godonline
Messages postés2Date d'inscriptiondimanche 9 mars 2008StatutMembreDernière intervention22 mars 2009
-
21 mars 2009 à 21:57
NHenry
Messages postés15112Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention13 avril 2024
-
22 mars 2009 à 14:02
Bonjour,
J'essaie depuis quelques jours de créer une dll afin de pouvoir alimenter une table de données sous sql server. Je me suis basé à cet effet sur un tutoriel exposé ici http://www.codersource.net/c++_ado_stored_procedure.html Voici mon code :
#include //This program uses MFC
#include
#include <stdio.h>
/*The following variables will be initialized with necessary values and appended to the strSQL values*/
_bstr_t strName;
_bstr_t strAge;
_bstr_t strDOB;
_bstr_t strSalary;
//Open the SQL Server connection
hr = pConn->Open(strCon,"","",0);
if(FAILED(hr))
{
printf("Error Opening Database object\n");
goto cleanup;
}
//Create the C++ ADO Command Object
pCom.CreateInstance(__uuidof(Command));
pCom->ActiveConnection = pConn;
//Make the ADO C++ command object to accept stored procedure
pCom->CommandType = adCmdStoredProc ;
//Tell the name of the Stored Procedure to the command object
pCom->CommandText = _bstr_t("dbo.spTestTable");
//Prepare the Name VARIANT for ADO C++ Command Object Parameter
VARIANT vName;
vName.vt = VT_BSTR; //Variant type for BSTR
vName.bstrVal = _bstr_t("CoderSource C++ ADO Stored Procedure Sample");
//Prepare the Age VARIANT for ADO C++ Command Object Parameter
VARIANT vAge;
vAge.vt = VT_I2; //Variant type for Integer
vAge.intVal = 10;
//Prepare the Salary VARIANT for ADO C++ Command Object Parameter
COleCurrency vOleSalary(5000,55);
//Use COleDateTime class for Date type
COleDateTime vOleDOB( 2004, 2,1 , 0, 0 , 0 ) ;
//Add Parameters to the C++ ADO Command Object
//This adds the string parameter
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("strCompanyName"),adChar,adParamInput,50,vName));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("iAge"),adInteger,adParamInput,4,vAge));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("dob"),adDate,adParamInput,8,_variant_t(vOleDOB)));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("mSalary"),adCurrency,adParamInput,8,_variant_t(vOleSalary)));
En tentant de compiler ce code j'obtiens le code d'erreur suivant :
-------------------Configuration: test - Win32 Debug--------------------
Compiling...
StdAfx.cpp
c:\program files\microsoft visual studio\myprojects\test\debug\msado15.tlh(407) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
c:\program files\microsoft visual studio\vc98\include\comip.h(46) : error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file
Error executing cl.exe.
StdAfx.obj - 1 error(s), 1 warning(s)
Existe t il un moyen simple de résoudre ce problème. Voici encore qq détails :
- Il s'agit d'une MFC Application (dll)
-User et Password remplacent mes véritables login windows pour accéder à ma base de données sql server.
-Je n'ai utilisé dans le code que le fichier .cpp
En espérant que ces détails vous permettront de m'aider.