[英]How can I store a string in a varbinary(max) column using c#
How can I store a string in a varbinary(max) column? 如何将字符串存储在varbinary(max)列中?
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). 如果要存储字符串,请使用[n] varchar(max)。
If you must use varbinary(max), then to get the bytes you must use an encoding, for example: 如果必须使用varbinary(max),那么要获取字节,必须使用编码,例如:
byte[] theBytes = Encoding.UTF8.GetBytes(theString);
and later: 然后:
string theString = Encoding.UTF8.GetString(theBytes);
(when reading) (阅读时)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.