Reputation: 21
I was Searching For Result in Stackoverflow this what i found but still have a problem :" For the field to be able to store unicode characters, you have to use the type nvarchar (or other similar like ntext, nchar).
To insert the unicode characters in the database you have to send the text as unicode by using a parameter type like nvarchar / SqlDbType.NVarChar.
(For completeness: if you are creating SQL dynamically (against common advice), you put an N before a string literal to make it unicode. For example: insert into table (name) values (N'Pavan').)"
My Problem is that in my codes storing is like this : String Name = Text1.Text; SqlCommand cmd = new SqlCommand("Insert into Tablex values (Name)",con); if i put N before Name it Point to another string that need initializing so what can i do any help please
Upvotes: 1
Views: 1434
Reputation: 21
Ok So Heres what i found and it worked : Only Nvarchar,ntext or nchar works no need to do collation all we have to do in codes are the following : insert into table (name) values (N'Pavan') or in my case of putting the textfield in a string then : "insert into Tablex values(N'" + Mname + "','" + Mp + "','" + Ln + "','" + Mc + "','" + ML + "')"; the N'" cast next input as Utf so it recognize arabic thanks everyone for the help
Upvotes: 1
Reputation: 52260
You're worrying about the wrong layer; c# strings are already compatible with Unicode strings (as well as other encodings) since they are stored as UTF-16. You do not have to worry about the encoding from a c# perspective.
You need to worry about the encoding on the database. Define the table schema with NVarChar as the column type, and if you use any stored procedures, you need to define any string parameters as NVarChar. Be sure to bind any parameters using SqlDbType "NVarChar".
Also, make sure SQL Server is using an appropriate collation.
Upvotes: 3