Click here to Skip to main content
15,903,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Local machine ip address Pin
lucy12-Sep-02 5:43
lucy12-Sep-02 5:43 
GeneralScripting for Applications Pin
Ciufudean Sorin12-Sep-02 2:16
Ciufudean Sorin12-Sep-02 2:16 
QuestionHow to check if field value is NULL? Pin
anju12-Sep-02 1:53
anju12-Sep-02 1:53 
AnswerRe: How to check if field value is NULL? Pin
Imran Farooqui12-Sep-02 2:12
Imran Farooqui12-Sep-02 2:12 
GeneralRe: How to check if field value is NULL? Pin
anju12-Sep-02 18:39
anju12-Sep-02 18:39 
GeneralRe: How to check if field value is NULL? Pin
Imran Farooqui12-Sep-02 19:06
Imran Farooqui12-Sep-02 19:06 
AnswerRe: How to check if field value is NULL? Pin
Rama Krishna Vavilala12-Sep-02 2:09
Rama Krishna Vavilala12-Sep-02 2:09 
AnswerRe: How to check if field value is NULL? Pin
[James Pullicino]12-Sep-02 2:36
[James Pullicino]12-Sep-02 2:36 
This line:
<br />
(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Test")->Value); <br />


is very dangerous because of the following reasons:

If Fields fails, an exception will be thrown.
If GetItem fails, an exception will be thrown.
If Value cannot be converted to a _bstr_t, an exception will be thrown.

Segment your code a little better. Add exception handling, or use the raw_ methods of your smart pointers. Here is an example on how to improve your code (this is from memory):

<br />
IFieldPtr field;<br />
try<br />
{<br />
  field = pRecordset->Fields->GetItem("Test");<br />
} <br />
catch(com_error e) <br />
{ <br />
  field = NULL;<br />
}<br />
<br />
if(field != NULL)<br />
{<br />
  _variant_t vtVal;<br />
  try<br />
  {<br />
    vtVal = field->Value;<br />
  } catch (_com_error e) {vtVal.vt = VT_ERROR; }<br />
  <br />
  _bstr_t bstrVal;<br />
  if(vtVal.vt != VT_ERROR)<br />
  {<br />
     try{ bstrVal = (_bstr_t)vtVal; }<br />
     catch(com_error e) {bstrVal = L"";}<br />
  }<br />
  <br />
  AfxMessageBox((LPCTSTR)bstrVal);<br />
}<br />
<br />



--James

Drinking In The Sun
Forgot Password?
GeneralRe: How to check if field value is NULL? Pin
anju12-Sep-02 18:44
anju12-Sep-02 18:44 
GeneralRe: How to check if field value is NULL? Pin
anju12-Sep-02 18:51
anju12-Sep-02 18:51 
GeneralMFC and old functions Pin
Tolias12-Sep-02 1:38
Tolias12-Sep-02 1:38 
GeneralRe: MFC and old functions Pin
Tomasz Sowinski12-Sep-02 1:42
Tomasz Sowinski12-Sep-02 1:42 
GeneralRe: MFC and old functions Pin
Anonymous12-Sep-02 1:52
Anonymous12-Sep-02 1:52 
GeneralRe: MFC and old functions Pin
Tomasz Sowinski12-Sep-02 1:54
Tomasz Sowinski12-Sep-02 1:54 
GeneralRe: MFC and old functions Pin
Tolias12-Sep-02 1:59
Tolias12-Sep-02 1:59 
GeneralRe: MFC and old functions Pin
Tomasz Sowinski12-Sep-02 2:03
Tomasz Sowinski12-Sep-02 2:03 
GeneralRe: MFC and old functions Pin
Michael P Butler12-Sep-02 1:44
Michael P Butler12-Sep-02 1:44 
GeneralCompiler directives Pin
Ruca12-Sep-02 1:20
Ruca12-Sep-02 1:20 
GeneralRe: Compiler directives Pin
Tomasz Sowinski12-Sep-02 1:29
Tomasz Sowinski12-Sep-02 1:29 
GeneralOuput data Pin
Kash12-Sep-02 1:15
Kash12-Sep-02 1:15 
GeneralRe: Ouput data Pin
Christian Graus12-Sep-02 2:10
protectorChristian Graus12-Sep-02 2:10 
GeneralRe: Ouput data Pin
Jawache12-Sep-02 3:28
Jawache12-Sep-02 3:28 
GeneralSplitter Window with 2 views with MFC Pin
Chun Te, Ewe12-Sep-02 0:58
Chun Te, Ewe12-Sep-02 0:58 
GeneralRe: Splitter Window with 2 views with MFC Pin
Jawache12-Sep-02 1:14
Jawache12-Sep-02 1:14 
GeneralRe: Splitter Window with 2 views with MFC Pin
JohnnyG12-Sep-02 2:37
JohnnyG12-Sep-02 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.