================================== Declaration ==================================
This article is original, reproduced in the text of the influential annotated author and source, and to ensure the integrity of the article.
Do not modify (including this statement) without the consent of the author, and reserve the right of legal investigation.
Do not use for publication, printing or academic reference without the consent of the author.
In order to ensure the correct contents, we suggest that we should read the original text.
This article link: http://www.cnblogs.com/wlsandwho/p/4352764.html
=======================================================================
does not contain any error handling and exception handling, write-only critical code.
=======================================================================
The database used for testing
TestDB
Login name and password for testing
Testdev
123456
Contents of the Sqlserver_ed.udl file for testing
1 [OLE DB] 2 This is An OLE DB initstring 3 provider=sqloledb. 1; password=123456; Persist Security info=true; User id=testdev;initial Catalog=testdb;data source=thbytwo-pc-test\sqlexpress
=======================================================================
A table for testing
CREATE TABLE testtable (id int null,val int NULL)
Stored procedures for testing
1CREATEproc proc_testproc @id @val int2 as 3 insert into Dbo.testtable4 (ID, Val) 5 @id, -- Id-int6 @val -- Val-int7)
=======================================================================
Simple connect and insert operations using only connection objects.
1 CoInitialize (NULL);2 3 _connectionptr pconnection;4Pconnection.createinstance (TEXT ("ADODB. Connection"));5 6Pconnection->connectionstring=text ("File name=sqlserver_ed.udl");7pconnection->commandtimeout=Ten;8pconnection->cursorlocation=adUseClient;9Pconnection->mode=adModeUnknown;TenPconnection->open (TEXT (""), TEXT (""), TEXT (""), adconnectunspecified); One A CString Strinsert; -Strinsert.format (TEXT ("Insert into testtable values (%d,%d)"),5,6); - thePconnection->Execute (_bstr_t (Strinsert), null,adcmdtext); - -Pconnection->Close (); -pconnection-. Release (); + -CoUninitialize ();
Using stored procedures with parameters for the same insert operation
To eat.
SQL Server r2--vc++ ADO operations