Microsoft KB Archive/229088: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 80: | Line 80: | ||
</pre> | </pre> | ||
To read a field value that could be SQL NULL, you must test it for VT_NULL. The following code snippet demonstrates this: | To read a field value that could be SQL NULL, you must test it for VT_NULL. The following code snippet demonstrates this: | ||
<pre class="codesample">_variant_t v(rs->Fields->Item[_variant_t( | <pre class="codesample">_variant_t v(rs->Fields->Item[_variant_t("StudName")]->Value); | ||
if( v.vt == VT_NULL){ | if( v.vt == VT_NULL){ | ||
....// Field is SQL NULL | ....// Field is SQL NULL |
Latest revision as of 13:44, 21 July 2020
Article ID: 229088
Article Last Modified on 8/9/2004
APPLIES TO
- Microsoft ActiveX Data Objects 2.0
- Microsoft ActiveX Data Objects 2.1
- Microsoft ActiveX Data Objects 2.5
- Microsoft ActiveX Data Objects 2.6
- Microsoft ActiveX Data Objects 2.7
- Microsoft Visual C++ 6.0 Enterprise Edition
This article was previously published under Q229088
SUMMARY
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.
MORE INFORMATION
The following file is available for download from the Microsoft Download Center:
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. To send a SQL NULL parameter, create a _variant_t and then change the type to VT_NULL. The following code snippet shows this:
_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
REFERENCES
For additional information, please see the following articles in the Microsoft Knowledge Base:
182389 FILE: Adovcbm.exe ADO 1.5 with #import and Getrows/Bookmarks
184968 FILE: Adovcsp.exe Demonstrates Using Stored Procedures with ADO
181733 FILE: Adovcbtd.exe #import Using UpdateBatch and CancelBatch
220152 FILE: Sample: ADOVC1 Simple ADO/VC++ Application
200122 SAMPLE: ATL2ADO returns disconnected recordset from COM to VB
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Rick Anderson, Microsoft Corporation.
Keywords: kbhowto kbdatabase kbfile kbsample KB229088