Solved

CDaoDatabase: how to know if value of a field is empty?

Posted on 2000-02-26
8
191 Views
Last Modified: 2013-11-20
Hi,

in a .mdb database, the value of a field may be empty, that is , nothing in that field (actually, since the database initially is not created by me, so i dunno whether it is " " or just leave it empty there). is there any way to check whether it is empty?
i had use
COleVariant v1;

v1=rs.GetFieldValue(ex_fd[0]);
s1=(char *)v1.bstrVal;

to get the value .. however if i use strcmp(s1," ")==0) to check. it gives error....

pls help me!!! thanks a lot!
0
Comment
Question by:greenbird
  • 3
  • 3
  • 2
8 Comments
 
LVL 1

Expert Comment

by:hiap_ho
ID: 2567067
You should be able to use strcmp, however usually I would use it in the following manner

CString s1;
s1=(LPTSTR)v1.bstrVal;
if(!strcmp(s1,""))blablabla;
blablabla == action taken when s1 is empty string.

hope this will help
0
 

Author Comment

by:greenbird
ID: 2567668
Hi,

well the problem is that i can not use strcmp( it is only my opinion) since actually there is nothing in the field... so how to check it is EMPTY initially ? can strcmp(NULL...)? thanks!
0
 
LVL 1

Expert Comment

by:hiap_ho
ID: 2567706
nope
you can still check using strcmp, just use strcmp(s1,"") <--- will give you 0 if s1 is empty.
The mistake is probably lies on
s1=(char *)v1.bstrVal;

change that line to
use CString instead of char*
CString s1;
s1=(LPTSTR)v1.bstrVal;

another way to test if
if(s1=="") <--- this will also work if you use CString

hope that will help

0
 
LVL 1

Expert Comment

by:hiap_ho
ID: 2567719
anyway you can still try to use char*

but use
strcpy(s1,(LPTSTR)v1.bstrVal);
or
strcpy(s1,(char*)v1.bstrVal);

I have not tested this method however it might just work.
Anyway
You cannot assign char* using "=" operator.

char* s1;
s1="baba" <=== not allowed
correct way should be
strcpy(s1,"baba");

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
V_Bapat earned 10 total points
ID: 2569028
Derive a class from CDaoRecordset for your table. This will give you a member variable of type CString.
Now when you move to the record, you can check IsEmpty() for that.
0
 

Author Comment

by:greenbird
ID: 2571121
Hi,

could u pls illustrate it by some code? which member variable? sorry i am new to VC++, so know little abt db... thanks a lot!
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2571757
Derive a class from CDaoRacordset. Select the DAO in Datasource and provide your mdb filename. From the displayed list of tables for that database select the table for which you want to create the recordset.

This will give you member variables for all the fields which you can use directly instead of using GetFieldValue and SetFieldValue.

Suppose there is one text field 'Name' in your table, you will get (or you specify) the member variable m_Name, then you can use it as any other member variable.

CMyRecordset rs;  //CMyRecordset is derived from CDaoRecordset
rs.Open();
if(rs.m_Name.IsEmpty())
{
.....
}
else
{
.....
}


This method is RFX. Check out the technical articles(TNXXX where XXX is the article no) from MSDN on databases.
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2586533
Oooops! It is DFX and not RFX.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 64
NotAlone Challenge 20 72
Execute multiple curl cmds with sleep and send output to file 10 80
Path of Workbook 3 45
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now