|
Hi all,
How to check if field value is NULL?
In my application i am using the code as follows to get the Recordset field value
while (VARIANT_FALSE == pRecordset->EndOfFile)
{ strTemp.Format("Test Column:%s",
(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Test")->Value);
AfxMessageBox(strTemp);
pRecordset->MoveNext();
}
while running the application if the Field value is NULL. I am getting Runtime Error
as "abnormal Programme termination".
please help me
anju
|
|
|
|
|
Consider query:
select nick from from mytable .
Suppose the value represented by nick can be NULL. So change the query as:
select isnull(nick, 'something') as nick from mytable
Here 'something' can be anything you desire. This can be a single space character also. Now when you collect value of nick from Recordset object, it'll not be null but the value supplied by you as a parmeter above. You can check it and treat as NULL
Imran Farooqui
World first Urdu Instant Messenger[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Java is a tool for creating applications that torture users with its awful speed and its ugly interfaces.
Daniel Turini commenting on this article
|
|
|
|
|
Hi Imran Farooqui,
Thanks for Your Reply.
Please need more help to me..............
Suppose i have to select entire table then how can i make all null fields in the table to 'Something'.
in my application i am opening the recordset as follows
pRecordset->Open("mytable",
_variant_t((IDispatch*)pConnection,true),
adOpenDynamic, adLockPessimistic,adCmdTable);
and i am getting all the fields
pRecordset->MoveFirst();
while (!pRecordset->EndOfFile)
{
strTemp.Format("Field1:%s",(LPSTR)(_bstr_t)pRecordset->Fields->GetItem("Field1")->Value);
AfxMessageBox(strTemp);
pRecordset->MoveNext();
}
anju
|
|
|
|
|
In your code, you'r opening a complete table using RecordSet object. I do not prefer this technique because you have no control over the selected records. Instead i prefer to explicitly open the table using SQL queries.
m_pRecordSet = m_pConnection->Execute("select * from mytable", &vRecsAffected, adOptionUnspecified);
Only if you are accessing the table in this way, you can use, isnull option.
Imran Farooqui
World first Urdu Instant Messenger[^]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Java is a tool for creating applications that torture users with its awful speed and its ugly interfaces.
Daniel Turini commenting on this article
|
|
|
|
|
You need to do something like this.
_variant_t vt = pRecordset->Fields->GetItem("Test")->Value;
if (vt.vt == VT_NULL)
{
AfxMessageBox("Field is NULL");
}
else
{
strTemp.Format("Test Column:%s",(LPSTR)(_bstr_t)vt);
AfxMessageBox(strTemp);
}
C# is fundamentally broken. - Christian Graus
|
|
|
|
|
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?
|
|
|
|
|
Hi Rama Krishna,
ThankQ this technique is work to me well
anju
|
|
|
|
|
Hi James Pullicino,
Thanks a lot..
I never thing about what u pointed.
now my code is changed as per your instructions.
once again thank to you
anju
|
|
|
|
|
I need to ask a question that's been bothering me for some time now. I created an SDI application from the Visual C++ wizard. Everything was fine then. When I added a function (that someone else) created in old C, all of a sudden the menu and status bar dissapeared and I haven't seen them since then. I get no errors after building the project but I can't make the bars appear, neither through menu->view nor with right clicking. Could it be that some old function (like atoi) has a side-effect on the program? All functions in the old C file are global to the project.
|
|
|
|
|
Sounds strange. 'Old functions like atoi' shouldn't have any side-effects. What is the purpose of function you've added?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
It reads two files containing neurules definitions and variable definitions, asks the user to insert values to variables and then uses the neurules to make an inference. It also evaluates the rules if needed. My part was to convert all the 'printf' calls to something visual.
|
|
|
|
|
At what point exactly are you calling this function? Are you using dialogs for entering variables' values?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Well, this function was originally writen in C with a console user interface. I erased all printf and scanf calls and used dialogs to prompt messages and get input. The function is called inside ON_OPTIONS_INFERENCE.
|
|
|
|
|
It shouldn't have side-effects you've described. I guess you'll have to look for the cause of problems by commenting out parts of the code or inserting temporary return statements.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Put a breakpoint in the CMainFrame::OnCreate function. This is where the toolbar and status bar should be created. It should give you more of a clue to why they have gone.
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
Hi,
I have 2 projects ( project A and B)which use most of the same functions, but there are others which are unique to project A and others to B.
I would like to be able to use a #define to compile Project A with its own functions and then by changing the #define compile project B with its functions. In other words, I would like to avoid defining 2 different projects.
Is this possible?
And how does one do it, both in the header and source code files?
Thanking you in anticipation.
Rui
|
|
|
|
|
You can use #ifdef and friends for conditional compilation. Your other option is to create a library containing common code.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
I am running numerical code and want to print the results in a scrollable edit box and I want to save this data in an array?
Any ideas?
Kash
|
|
|
|
|
iostreams - check out my articles here on CP.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Too Vague Kash.
Ask something more specific or give more details.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Dear All,
I would like to have 2 different views for a document. Each view to be display one at a time or together using a splitter window at any point of time.
How best should I approach this? I'm open to any new ideas.
I've just started programming and I think my question will be trivial to most of you out there. Thanks very much for taking the time to help me out
Regards,
Chun Te
|
|
|
|
|
If when you say different views you mean, different view classes, then you should use a Splitter Window and create static views, look at MSDN.
Its difficult to create a Static Splitter window which can turn into a single window since the Splitter Asserts if there is only once view. have a look in the Splitter Section of codeproject.. there might be some ideas you can use.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
I've used this class, ST_SplitterWnd,to do just what you want. I have two views which are the same because the view has a tab control. The dual views allows the user to see two different tabs of data at once, if desired.
It is here on Code Project in the Articles section. BTW, the class has a nice function called ToggleSide() which allows hiding one of the views. Thus, you can add both views and hide one and the user only sees one. But, when the user wants a second view, you just call ToggleSide() again.
|
|
|
|
|
Hi,
I have written a MFC Extended dll.It works fine in Debug mode.In Release mode if i use /MDd it works.But if i use /MD it crashes. Could any one pl tell me why is it happening so?
Thanks
Neha
|
|
|
|
|
You have probably screwed something with project settings. What exactly crashes?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|