chikersal
asked on
how to handle null
sir using ado i retrieve alues from a field like this
_ConnectionPtr con;
_RecordsetPtr rec;
con.CreateInstance(__uuido f(Conectio n));
con->Open() // to connect to the data source
rec.CreateInstance(__uuido f(Recordse t));
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_pho ne)
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_pho ne)
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
_ConnectionPtr con;
_RecordsetPtr rec;
con.CreateInstance(__uuido
con->Open() // to connect to the data source
rec.CreateInstance(__uuido
rec->PutRefActiveConection
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"
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_pho
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_pho
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11443178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11964778
https://www.experts-exchange.com/jsp/qShow.jsp?qid=12043279
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11564958
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104338
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104344
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20105195
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20107021
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20117736
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20123376
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20128779
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11146525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11559878
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11540439
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20158555
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174325
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20176309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20177269
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20183746
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20188568
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260766
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260773
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20262003
Thanks,
Netminder
Community Support Moderator
Experts Exchange
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.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11443178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11964778
https://www.experts-exchange.com/jsp/qShow.jsp?qid=12043279
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11564958
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104338
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20104344
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20105195
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20107021
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20117736
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20123376
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20128779
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11146525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11559878
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11540439
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20158555
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174325
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20176309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20177269
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20183746
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184309
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20188568
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260766
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20260773
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20262003
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
ASKER
lstrcpy(str,(_bstr_t)v_pho
}
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