Solved

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

Posted on 2000-02-26
9
189 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 194
difference between String.subString() and String.subSequence() 6 234
wordmultiple challenge 12 141
Problem to open Excel file 15 173
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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