繁体   English   中英

如何使用c#将字符串存储在varbinary(max)列中

[英]How can I store a string in a varbinary(max) column using c#

如何将字符串存储在varbinary(max)列中?

我在转换过程中遇到麻烦我正在这样做:

    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);

如果要存储字符串,请使用[n] varchar(max)。

如果必须使用varbinary(max),那么要获取字节,必须使用编码,例如:

byte[] theBytes = Encoding.UTF8.GetBytes(theString);

然后:

string theString = Encoding.UTF8.GetString(theBytes);

(阅读时)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM