I have a string in UTF8 like:
Thermal Oxide: 0 Å to 40 μm
and I want to save it in SQL Server.
When I save it in data type ntext/nvarchar - it saves like this:
Thermal Oxide: 0 ? to 40 ?m
What can I do?
用N
引用带引号的字符串:
INSERT INTO someTable (myField) VALUES (N'Thermal Oxide: 0 Å to 40 μm')
I have a string in UTF8 like:
Actually, no you don't - you have a unicode string. UTF8, however, only applies to how it is encoded, ie storage. If you mean you want to store it, fine; simply: make sure the column you store it in is nvarchar(somelen)
(or similar), and that you use parameters to store it. If you just use cmd.Parameters.AddWithValue("paramName", yourString);
that'll be fine (for TSQL like insert [tablename] (...fields...) values (..., @foo)
etc). Likewise, any ORM / micro-ORM / other database tool will work fine with this, as long as the column is nvarchar(somelen)
or similar. For example, with "dapper":
string s = "Thermal Oxide: 0 Å to 40 μm";
connection.Execute("insert [tablename] (colname) values (@s)", new {s});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.