How can I store a string in a varbinary(max) column?
I'm havig trouble in the convertion process i'm doing this:
cmd.CommandText = "Insert into " + bdcombo.Text + ".dbo.nomes (id, nome) values (@id, @nome)";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
cmd.Parameters.Add("@nome", SqlDbType.VarBinary, 20).Value = Convert.ToSByte(textBox1.Text);
If you want to store a string, use [n]varchar(max).
If you must use varbinary(max), then to get the bytes you must use an encoding, for example:
byte[] theBytes = Encoding.UTF8.GetBytes(theString);
and later:
string theString = Encoding.UTF8.GetString(theBytes);
(when reading)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With