Solved

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

Posted on 2000-02-26
9
181 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

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

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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