I have a stored procedure in SQL Server that inserts a row into a table. One
of the columns of the table has the "image" data type, which maps to a byte
array in ADO SqlClient.

The problem I have is that the data that I'm adding as a parameter when
calling the stored procedure comes from a TextBox on the web page, which is
of type string. As a result, I keep getting errors because it can't convert
a string to a byte array. I cannot seem to find any kind of method that
would do that for me.

Does anyone know what would be the correct procedure to pass data for
inserting into a column of type image, when the data is coming as a string
from a text box?

Or, if nothing else, how could I convert a string to a byte array?

Thanks

Re: Inserting string into SQL Server image column by Jouni

Jouni
Sat Jul 24 00:37:08 CDT 2004

"Marcio Kleemann" <notavailable> wrote in
news:ekjgckQcEHA.1568@TK2MSFTNGP10.phx.gbl:

> I have a stored procedure in SQL Server that inserts a row into a
> table. One of the columns of the table has the "image" data type,
> which maps to a byte array in ADO SqlClient.
> The problem I have is that the data that I'm adding as a parameter
> when calling the stored procedure comes from a TextBox on the web
> page, which is of type string. As a result, I keep getting errors
> because it can't convert a string to a byte array. I cannot seem to
> find any kind of method that would do that for me.

So, umm, _why_ do you have an image field that's filled from a TextBox?
What is that data you're typing into the field? If it's stored in the DB as
text, why not use the SQL Server's Text data type?

Converting a string to a byte array isn't hard, but it may easily result in
unwanted encoding issues if your string contains 8-bit characters. Anyway,
Encoding.GetBytes is your friend there.


--
Jouni Heikniemi, jouni-news@heikniemi.net
http://www.heikniemi.net/hc/ (blog)

Re: Inserting string into SQL Server image column by Marcio

Marcio
Sun Jul 25 13:08:24 CDT 2004

Thanks. Encoding.GetBytes seems to do the job.

There actually is a reason why we need to use the image data type, so the
conversion from string accomplished what I needed to do.

"Jouni Heikniemi" <jouni-news@heikniemi.net> wrote in message
news:Xns953057AA031ABjouninews2heikniemin@127.0.0.1...
> "Marcio Kleemann" <notavailable> wrote in
> news:ekjgckQcEHA.1568@TK2MSFTNGP10.phx.gbl:
>
> > I have a stored procedure in SQL Server that inserts a row into a
> > table. One of the columns of the table has the "image" data type,
> > which maps to a byte array in ADO SqlClient.
> > The problem I have is that the data that I'm adding as a parameter
> > when calling the stored procedure comes from a TextBox on the web
> > page, which is of type string. As a result, I keep getting errors
> > because it can't convert a string to a byte array. I cannot seem to
> > find any kind of method that would do that for me.
>
> So, umm, _why_ do you have an image field that's filled from a TextBox?
> What is that data you're typing into the field? If it's stored in the DB
as
> text, why not use the SQL Server's Text data type?
>
> Converting a string to a byte array isn't hard, but it may easily result
in
> unwanted encoding issues if your string contains 8-bit characters. Anyway,
> Encoding.GetBytes is your friend there.
>
>
> --
> Jouni Heikniemi, jouni-news@heikniemi.net
> http://www.heikniemi.net/hc/ (blog)