Solved

how to get the string value of a field of type NUMBER in .mdb database file?

Posted on 2000-02-26
9
184 Views
Last Modified: 2013-11-20
Hi,

in a .mdb database file, there are two fields of type NUMBER, now i want to get the string value of the field, how to do that? also how to get the value of the number directly? that is, if the value is 92, then i wnat to have a int int_var = 92 returned... how to do that?

PLS help me!!! thanks a lot!
0
Comment
Question by:greenbird
9 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2560752
Depends
what interface you use ?
DAO or plain OBDC ?
0
 
LVL 3

Expert Comment

by:akalmani
ID: 2560753
Hi !!
  I don't know if any function is available for it. But i do have a method

Get the value in int datatype and convert that int to string.

0
 
LVL 1

Expert Comment

by:RAVID
ID: 2560756
Hi,

U can use sscan(char *, "%d",&nInt);
where Char * contains the string whose integer value to be found and nInt is an integer.

Now to get the string value u can connect to the database using DSN and put member variables to them. Now u can use GetWindowText(); and get that value.

Cheers
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2560759
HI,

U will get it in the number form easily.
Just say
int Value = UrTablePointer->fieldNamewhichcontains92asvalue;

TO convert it to string I will say

CString l_strVal;
l_strVal.Format("%d", Value);

Then l_strVal, will contain the string converted value.
Try ot out.

VinExpert
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:greenbird
ID: 2560823
Hi,

well i do not think u had understood my qn, let me state it clearly :)

i use the following to get the the string value of such a field:

COleVariant v1;
char *s1;

v1=rs.GetFieldValue(field_name);
s1=(char *)v1.bstrVal;

however the system always got error, seems it can not get the string value... is it that i shld not use bstrVal? or
.....?

Pls help!
0
 

Accepted Solution

by:
noogie6 earned 10 total points
ID: 2561797
I think you're looking at the wrong field in your variant datatype. It would seem very odd to me that whatever database driver you're using would put a number field from your database into a bstrVal which is for strings. You got two options here. Change your database or convert in your C++ code.

HTH, Noogie
0
 

Expert Comment

by:noogie6
ID: 2561806
Oh, by the way, casting a BSTR to a char * will give you errors too. You need to use a macro for this I think, it's in MSDN somewhere

Noogie
0
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2563504
get the number value from your .mdb database as integer or BYTE whatever.

int val1;

//suppose your number from
//the database has been retrived in val1

char str_val1[10];
 _itoa(val1,str_val1,10);
MessageBox(str_val1);

//see if str_val1 has what you need

Niraj





0
 

Author Comment

by:greenbird
ID: 2563827
Hi,

well i do not think u understood my qn. what i want is: how to get the integer value or the string value for a field? using COleVariant v1, what is the correct attribute to pass to v1 to get the int value?? (eg, use v1.bstr to get the string value)..

thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

13 Experts available now in Live!

Get 1:1 Help Now