Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-02-26
8
Medium Priority
?
201 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
[X]
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
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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
 
LVL 3

Accepted Solution

by:
V_Bapat earned 30 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

721 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