convert a string to a binary

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I'm trying to convert a string to a binary format (byte)
I've looked at BitConverter class, but I can't figure out how to use it
for a Strin.
Does anyone know ?

Thx
 
to a byte array

System.Text.Encoding.UTF8.GetBytes(strThestring)

from a byte array to a string

System.Text.Encoding.UTF8.GetString(bytArr)



happy coding

michel [MCP]
 
Sam said:
I'm trying to convert a string to a binary format (byte)
I've looked at BitConverter class, but I can't figure out how to use it
for a Strin.

'System.Text.Encoding.<encoding name>.GetBytes'.
 
I've tried this :

row("Password") = System.Text.Encoding.Unicode.GetBytes(txtPwd1.Text)

(row is type System.Byte)

And I get the following exception :

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: System.InvalidCastException: Specified cast is
not valid.
at System.Convert.ToByte(Object value)
at System.Data.Common.ByteStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object
value)Couldn't store <System.Byte[]> in Password Column. Expected type
is Byte.


What's going on ? Apparentely GetBytes return an array of bytes but it
seems I want just a byte. Actually I'm not so sure about that. In my
database, this field is of type Binaries, so is Byte the right type in
VB ?
Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top