[英]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.