SQL Server 2008 R2——VC++ ADO 操作

來源:互聯網
上載者:User

標籤:

==================================聲明==================================

本文原創,轉載在本文中顯要的註明作者和出處,並保證文章的完整性。

未經作者同意請勿修改(包括本聲明),保留法律追究的權利。

未經作者同意請勿用於出版、印刷或學術引用。

本文不定期修正完善,為保證內容正確,建議移步原文處閱讀。

本文連結:http://www.cnblogs.com/wlsandwho/p/4352764.html

=======================================================================

不含任何錯誤處理和異常處理,僅寫關鍵代碼。

=======================================================================

用於測試的資料庫

testdb

用於測試的登入名稱和密碼

testdev

123456

用於測試的sqlserver_ed.udl檔案內容

1 [oledb]2 ; Everything after this line is an OLE DB initstring3 Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=testdev;Initial Catalog=testdb;Data Source=THBYTWO-PC-TEST\SQLEXPRESS

=======================================================================

用於測試的表

CREATE TABLE  testtable(id   int NULL,val int NULL)

用於測試的預存程序

1 CREATE PROC proc_testproc @id INT, @val INT2 AS 3     INSERT    INTO dbo.testtable4             ( id, val )5     VALUES    ( @id, -- id - int6               @val  -- val - int7               )

=======================================================================

 簡單的僅使用 連線物件 進行 串連和插入 操作。

 1     CoInitialize(NULL); 2  3     _ConnectionPtr pConnection; 4     pConnection.CreateInstance(TEXT("ADODB.Connection")); 5  6     pConnection->ConnectionString=TEXT("File Name=sqlserver_ed.udl"); 7     pConnection->CommandTimeout=10; 8     pConnection->CursorLocation=adUseClient; 9     pConnection->Mode=adModeUnknown;10     pConnection->Open(TEXT(""),TEXT(""),TEXT(""),adConnectUnspecified);11 12     CString strInsert;13     strInsert.Format(TEXT("Insert into testtable values(%d,%d)"),5,6);14 15     pConnection->Execute(_bstr_t(strInsert),NULL,adCmdText);16 17     pConnection->Close(); 18     pConnection-.Release(); 19 20     CoUninitialize();

使用帶參數的預存程序進行同樣的插入操作

要吃飯了。

SQL Server 2008 R2——VC++ ADO 操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.