Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to handle null

Posted on 2001-09-17
5
262 Views
Last Modified: 2013-12-03
sir using ado i retrieve alues from a field like this

_ConnectionPtr con;
_RecordsetPtr rec;

con.CreateInstance(__uuidof(Conection));
con->Open() // to connect to the data source

rec.CreateInstance(__uuidof(Recordset));
rec->PutRefActiveConection(con);

rec->Open() // to open recordset using sql statement
               select emp_phone from employees

 Now this emp_phone field can contain NULL values also
 Then i use the following code to extract values from emp_phone

_variant_t v_phone;
v_phone=rec->GetCollect(L"emp_phone");

now this GetCollect() retrns value of type _variant_t which then gets stored in v_phone

then i use something like this

lstrcpy(str,(_bstr_t)v_phone)

and then i use str to show emp_phone's value

the point is that if emp_phone contains value
then lstrcpy() works fine

but if emp_phone's value is NULL
then if i use lstrcpy(str,(_bstr_t)v_phone)
the program gives error at run time
saying abnormal termination

so how should i find whether value in v_phone is null so that i dont use lstrcpy() in that case
0
Comment
Question by:chikersal
5 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 6487575
if(v_phone != NULL){
  lstrcpy(str,(_bstr_t)v_phone);
}
0
 

Author Comment

by:chikersal
ID: 6490572
if(v_phone != NULL){
 lstrcpy(str,(_bstr_t)v_phone);
}

instead of this what i tried was

if(v_phone==NULL) MessageBox(hwnd,"Null Values","Message",MB_OK);

but it never displayed the dialog box.

but anyway thanks for it
i will try again
if it does not work i will get back to you
thanks
0
 
LVL 2

Expert Comment

by:mirec
ID: 6494908
Hi chikersal,
have you tried:
if(v_phone.vt == VT_NULL) MessageBox(hwnd,"Null Values","Message",MB_OK);
?
I think that variant wrapper for NULL database values should have this type.

m.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6771973
chikersal,

You have a large number of questions have been open for some time, and our records show you logged in as recently as today. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11443178
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11964778
http://www.experts-exchange.com/jsp/qShow.jsp?qid=12043279
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11564958
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20104338
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20104344
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20105195
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20107021
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20117736
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20123376
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20128779
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11146525
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11559878
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11540439
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20158555
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20174325
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20176309
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20177269
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20183746
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20184309
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20188568
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20260766
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20260773
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20262003

Thanks,

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6788715
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question