473,728 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to convert _btsrt_t to string

Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codig o")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);
The first printf works ok and prints "As _bstr_t: 0001". The second one
hangs up the application... :(

I want to make this prints to be sure that convertion works well..

Any idea ?

Thanks in advance

J

PD: I'm using VC++ 6.0
Jul 23 '05 #1
2 1566
"Javier" <jl****@manresa .net> schrieb im Newsbeitrag news:ct******** **@news.ya.com. ..
Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codig o")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);


You cannot printf a std::string like that. One more reason to use streams. To print a std::string pass z.c_str() to printf.

HTH
Heinz
Jul 23 '05 #2
Heinz Ozwirk wrote:
"Javier" <jl****@manresa .net> schrieb im Newsbeitrag news:ct******** **@news.ya.com. ..
Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codig o")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);

You cannot printf a std::string like that. One more reason to use streams. To print a std::string pass z.c_str() to printf.

HTH
Heinz

It worked, thanks a lot !
J
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2982
by: Julius Mong | last post by:
Hi all, I'm doing this: // Test char code wchar_t lookup = {0x8364, 0x5543, 0x3432, 0xabcd, 0xef01}; for (int x=0; x<5; x++) { wchar_t * string = (wchar_t*) malloc(sizeof(wchar_t)); string = (wchar_t*)lookup; string = '\0'; CComBSTR bstrTest = SysAllocString(string); }
7
17879
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm able to encrypt and then decrypt data okay as in the following code: // encrypt the data // Encryptor enc = new Encryptor(EncryptionAlgorithm.TripleDes); byte key = Encoding.ASCII.GetBytes("0123456789012345");
2
2271
by: Joebloggs | last post by:
Hi I am trying to do an ldap lookup. I can pick up the domain name in the standard format DOMAIN\USERNAME. The problem is the company I work for expects the query in the format DOMAIN:USERNAME. I tried to do a simple string replace to replace \ to : but it turns out the only string you can't replace in c# is \ as it gives the error "Invalid Escape Sequence" - using "\\" or @"\" doesnt work either
25
4067
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
8
4277
by: toupeira23 | last post by:
Hello, I'm trying to encrypt passwords in my app. After discovering that there's no simple function to do this, I wrote a wrapper class which decodes a string using UTF8, encrypts it with TripleDES and returns a Base64-encoded string. The decryption function does the reverse, i.e. Base64-decodes the string, decrypts it with the same Key and IV, and encodes it again with UTF8. The problem is that after decrypting, the 8th character is...
5
3789
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
5
1438
by: ragavi | last post by:
Hi all i am trying to learn C# and .NET programming ..here is my program.. protected void btn_Save_Click(object sender, EventArgs e) { dbRead _dbRead = new dbRead(); dbTrans _dbTrans = new dbTrans(); try
3
1022
by: PGM | last post by:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Projname, ProjSpon As String Dim AppName, AppType, AppSupp, AppDesc As String Dim VendName, VendPhone As String Dim ReqName, ReqPurp As String
2
3014
by: E11esar | last post by:
Hello there. I am going in bit of a circle with this matter; First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line at a time into an array, using a string columns = line.Split(separators.ToCharArray()); command. Here is a definition of the table I am loading into:
0
8903
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9277
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9198
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6716
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3236
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2663
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2161
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.