SAMPLE: Vcspnp.exe Demonstrates Passing SQL NULL Parameters and Reading NULL Values with ADOID: Q229088
|
The Vcspnp.exe sample demonstrates correct handling of SQL NULL with Microsoft ADO using #import and Visual C++.
The sample demonstrates sending SQL NULL parameters to a SQL Server stored procedure with ADO. It also shows how to read SQL NULL values.
In SQL, NULL means having no value entered or unknown, completely different than a null C string. This sample shows how to package and send SQL NULL parameters to SQL Server stored procedure using ADO. It also shows how to read SQL NULL values.
The following file is available for download from the Microsoft
Software Library:
Vcspnp.exeRelease Date: May 14-1999
Q119591 How to Obtain Microsoft Support Files from Online Services
ReadMe.txt | 3579 |
resource.h | 1098 |
StdAfx.cpp | 208 |
StdAfx.h | 1171 |
VCSPNP.cpp | 2063 |
VCSPNP.dsp | 4163 |
VCSPNP.dsw | 535 |
VCSPNP.h | 1324 |
VCSPNP.rc | 5921 |
VCSPNPDlg.cpp | 13988 |
VCSPNPDlg.h | 2072 |
_variant_t vtNull;
vtNull.ChangeType(VT_NULL);
To read a field value that could be SQL NULL, you must test it for VT_NULL. The following code snippet demonstrates this:
_variant_t v(rs->Fields->Item[_variant_t("StudName")]->Value);
if( v.vt == VT_NULL){
....// Field is SQL NULL
For additional information, please see the following articles in the Microsoft Knowledge Base:
Q182389 FILE: Adovcbm.exe ADO 1.5 with #import and Getrows/Bookmarks
Q184968 FILE: Adovcsp.exe Demonstrates Using Stored Procedures with ADO
Q181733 FILE: Adovcbtd.exe #import Using UpdateBatch and CancelBatch
Q220152 FILE: Sample: ADOVC1 Simple ADO/VC++ Application
Q200122 SAMPLE: ATL2ADO returns disconnected recordset from COM to VB(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Rick Anderson, Microsoft Corporation.
Additional query words:
Keywords : kbfile kbsample kbADO kbADO200 kbDatabase kbVC kbVC600 kbGrpVCDB kbGrpMDAC
Version : WINDOWS:2.0,6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 20, 1999