Mã:
#include <windows.h>
#include <stdio.h>
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
/*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;
_ConnectionPtr pConn = NULL;
// Define string variables for ADO connection
_bstr_t strCon("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=username;Password=password;Initial Catalog=databasename;Data Source=(local);Integrated Security=SSPI;");
HRESULT hr = S_OK;
//Initialize the COM Library
CoInitialize(NULL);
try
{
//Create the Connection pointer
hr = pConn.CreateInstance((__uuidof(Connection)));
if(FAILED(hr))
{
printf("Error instantiating Connection object
");
goto cleanup;
}
//Open the SQL Server connection
hr = pConn->Open(strCon,"","",0);
if(FAILED(hr))
{
printf("Error Opening Database object using ADO _ConnectionPtr
");
goto cleanup;
}
/*Initialize the values */
strName = "'Codersource C++ ADO insert Sample',";
strAge = "10,";
strDOB = "'02/10/2004',";
strSalary = "1010.10)";
/* Append the values to the Insert Statement */
_bstr_t strSQL("Insert into Table1(Name,Age,DOBirth,Salary) Values(");
strSQL += strName + strAge + strDOB + strSalary ;
printf("%s
",(LPCSTR)strSQL);
//Execute the insert statement
pConn->Execute(strSQL,NULL,adExecuteNoRecords);
printf("Data Added Successfully
",(LPCSTR)strSQL);
//Close the database
pConn->Close();
}
catch(_com_error & ce)
{
printf("Error:%s
",ce.ErrorInfo);
}
cleanup:
CoUninitialize();
return 0;
}
View more random threads:
Ngoại trừ một số ít trường hợp rãnh mũi - má và “râu rồng silicon” xuất hiện sớm, có khi từ tuổi thanh niên do cơ địa, còn lại, đại đa số do căn do lão hoá đã gây nên ba diễn biến: Giảm mô xương gò...
Cách thẩm mỹ má ở tuổi trung niên...