468,738 Members | 2,463 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

How to convert a Byte array to a String

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
Nov 21 '05 #1
2 2017
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
Nov 21 '05 #2
"Jaime Stuardo" <js******@manquehue.net> 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/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Swarup | last post: by
6 posts views Thread by Ricardo Quintanilla | last post: by
15 posts views Thread by Kueishiong Tu | last post: by
6 posts views Thread by Allan Ebdrup | last post: by
6 posts views Thread by Bob Altman | last post: by
12 posts views Thread by Peter | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.