jack.li
jack.li

Reputation: 973

convert string to sql image type

I have c# app with sql database,in sql field type is image, but my c# app variable is string , how to store string var to image type in sql database?

parameters[10] = new OleDbParameter("@LONG_DESCRIPTION", sLongDes);
// sLongDes is string type, LONG_DESCRIPTION in sql is imag type
parameters[10].OleDbType = OleDbType.LongVarBinary;

this code is wrong.

Upvotes: 0

Views: 1261

Answers (1)

John Woo
John Woo

Reputation: 263713

you need to convert the string into Byte Array

byte[] array = Encoding.ASCII.GetBytes(sLongDes); // supports other encoding
parameters[10] = new OleDbParameter("@LONG_DESCRIPTION", array);
parameters[10].OleDbType = OleDbType.LongVarBinary;

Upvotes: 2

Related Questions