Solved

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

Posted on 2000-02-26
9
191 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
[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
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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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