Hi Guys,
I have a database table where the field is type integer.
In my program, i use

bstrTemp = static_cast< BSTR >(_myClass.m_QueryCommand.GetValue( 1 )   // using OLEDB consumer

the variable "bstrTemp" is type CComBSTR.

Lets say after retrieving the date from database, the value is 56(integer). When I execute the code above, bstrTemp will become "8" (string). How do I fill the value to integer type variable so that I get 56 (integer) instead of "8" (string)?
I'm stuck.. please advice..

Here is one way to convert it to integer. It may not work correctly if the string contains non-numeric digits so you will have to add some error checking.

#include <Windows.h>
#include <iostream>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
	BSTR bstrTemp = L"56";
	int x = 0;
	int len = wcslen(bstrTemp);
	for(int i = 0; i < len; i++)
	{
		x = ((x*10)+bstrTemp[i] - '0');
	}
	std::cout << x << '\n';
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.