ado讀取資料庫

2021-04-30 05:24:36 字數 603 閱讀 9324

當我們在使用ado運算元據庫的時候經常會碰到一些問題!例如資料庫為空我們就應該對是否為空做出判斷!

_variant_t var;

var =(_bstr_t)m_precordset->getcollect("z_controllersn");

if(var.vt != vt_null)

else

m_list.setitemtext(nitem,1,m_controllersn);

例如這段**就進行了判斷!但是這種判斷方法還是有錯誤的!為什麼呢!

主要的原因在於我們判斷資料庫為空是因為getcollect()這個函式的返回值是否為空!

當該值為空時就不能進行型別轉換了!否則程式會報錯!

所以我們不能為了省事而像上面這樣去寫ado運算元據庫的讀操作!

進行判斷後在型別轉換如下:

_variant_t var;

var =m_precordset->getcollect("z_controllersn");

if(var.vt != vt_null)

else

m_list.setitemtext(nitem,1,m_controllersn);

ADO 訪問資料庫

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system.window...

ADO資料庫示例

stdafx.h import c program files common files system ado msado15.dll no namespace rename eof nul adodlg.cpp coinitialize null connectionptr spconn uuid...

ADO資料庫顯示

pragma warning disable 4146 import c program files common files system ado msado15.dll no namespace rename eof adoeof todo add extra initialization he...