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?
Precede the quoted string with 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, i.e. 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});
new {s} as opposed to simply s? Also, the string s has a preceding single-quote but no close single-quote.s" - dapper uses that as the parameter name; new {s} represents an anonymous type with a string member s with value "Thermal ..." - everything we need to run it as a parameterised command
Nvarcharis definitely able to store this string - no problem at all.