PC Review


Reply
Thread Tools Rate Thread

How to convert a Byte array to a String

 
 
Jaime Stuardo
Guest
Posts: n/a
 
      6th Apr 2005
Hi all...

I'm trying to retrieve a SQLXML query using VB.NET. When I programmed in VB
6.0, I used Stream object to accomplish this which was trivial.

I cannot do the same thing in VB.NET. Here the most similar object is the
OleDbDataReader. I have the following method, żis it correct what I am
doing? By doing oRdr.GetBytes(0, 0, bBytes, 0, 1000) I'm limiting only to
1000 bytes. How can I know the length of the stream?

Public Function get_Tree(Optional ByVal sEstado As String = "") As String
Dim oConn As New OleDbConnection(m_sConn)
oConn.Open()
Dim oCmd As New OleDbCommand("SP_GET_CATEGORY_TREE", oConn)
Dim oParamEst As OleDbParameter = New OleDbParameter("@CAT_EST",
OleDbType.VarChar, Len(sEstado))
oParamEst.Value = sEstado
oCmd.Parameters.Add(oParamEst)
oCmd.CommandType = CommandType.StoredProcedure
Dim oRdr As OleDbDataReader = oCmd.ExecuteReader
If oRdr.Read Then
Dim bBytes(1000) As Byte
oRdr.GetBytes(0, 0, bBytes, 0, 1000)
Return "" ' I NEED TO RETURN THE XML THAT IS RETURNED FROM
THE SQL SP (AS FOR XML AUTO)
End If
End Function

Any help will be greately appreciated,
Jaime


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      6th Apr 2005
Jaime,

See this snippet.

\\\
"DataBase=Northwind; Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format("SELECT Photo FROM Employees WHERE (EmployeeID =
{0})", _
CInt(Session.Item("img")))
Dim cmd As New SqlClient.SqlCommand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDataReader = cmd.ExecuteReader()
rdr.Read()
Dim arrImage() As Byte = DirectCast(rdr.Item("Photo"), Byte())
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Dim ms1 As New System.IO.MemoryStream(arrImage)
'The one above is for normal purpose, however Northwind has a
strange format
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ms1 As New System.IO.MemoryStream(arrImage, 78,
arrImage.Length - 78)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim origimage As System.drawing.Image =
System.Drawing.Image.FromStream(ms1)
///
I hope this helps,

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      6th Apr 2005
"Jaime Stuardo" <(E-Mail Removed)> schrieb:
> I'm trying to retrieve a SQLXML query using VB.NET. When I programmed in
> VB 6.0, I used Stream object to accomplish this which was trivial.
>
> I cannot do the same thing in VB.NET. Here the most similar object is the
> OleDbDataReader. I have the following method, żis it correct what I am
> doing? By doing oRdr.GetBytes(0, 0, bBytes, 0, 1000) I'm limiting only to
> 1000 bytes. How can I know the length of the stream?


I cannot give you an answer on the database stuff. However, you can use
'System.Text.Encoding.<encoding name>.GetString' to convert a byte array to
a string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Byte Array to String craig.wagner@gmail.com Microsoft Dot NET 3 9th Nov 2005 04:26 AM
Convert byte array to string? =?Utf-8?B?RGF2ZQ==?= Microsoft C# .NET 5 10th Nov 2004 03:20 AM
Convert from byte array to string =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= Microsoft C# .NET 6 4th Nov 2004 05:59 PM
Convert byte array to string Dan Microsoft C# .NET 4 30th Aug 2004 08:09 PM
Re: Convert byte array to string Kumar Gaurav Khanna [.NET MVP] Microsoft Dot NET Framework 0 22nd Aug 2003 05:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.