how to insert unicode text to SQL Server from query window
The following should work, N
indicates a "Unicode constant string" in MSSQL:
INSERT INTO tForeignLanguage ([Name]) VALUES (N'Араб')
SQL Server 2012 not showing unicode character in results
Per the comment discussion on your question, your SQL code is correct and the unicode character is being updated, but SQL Server Management Studio cannot (for some reason) display this unicode character in the GRID resultset.
If you change your result view to TEXT (control+T), you should see the unicode character.
"If you use SSMS for your queries, change to output type from "Grid" to "Text", because depending on the font the grid can't show unicode."
- sql server 2008 not showing and inserting unicode characters
(ASP.NET MVC4 C#) Insert UNICODE to SQL Server
Any data access code should never be writing:
INSERT INTO [USER] ("username", "fullname")
VALUES ('admin', N'á')
because unicode aside, this is simply a SQL injection risk. Your data access should actually be doing something like
INSERT INTO [USER] ("username", "fullname")
VALUES (@username, @fullname)
adding parameters with those values. You don't make it clear what data access technology you are using, but it looks like either EF or LINQ-to-SQL, in which case the ORM will get this right. They all know all about unicode, and besides: the default (when adding a parameter with a string value) is to pass it over as unicode. You need to actually tell it to not do unicode. So I have to conclude that one of:
- the database column is
varchar
instead ofnvarchar
- the database column was
varchar
when you created the ORM model, and you haven't updated the model to tell it that it is nownvarchar
- so the model is working with what it knows, and adding the parameter as ANSI rather than unicode
Either fix the database column, or update the model to tell it that the column is unicode.
How to insert unicode (arabic) characters into SQL Server database
You should always use parametrized queries to avoid SQL injection attacks. Parameters also give you the ability to explicitly define what data types and which length you want. Furthermore, by using parameters, you don't need to fiddle with lots of single and double quotes and so forth - the code becomes much cleaner and easier to read - and you avoid a lot of errors, too!
Try code something like this:
// define your INSERT statement with PARAMETERS
string insertStmt = "INSERT INTO dbo.Table1(title, datee, post, cat, imageurl) " +
"VALUES(@title, @datee, @post, @cat, @imageurl)";
// define connection and command
using(SqlConnection conn = new SqlConnection(yourConnectionStringHere))
using (SqlCommand cmd = new SqlCommand(insertStmt, conn))
{
// define parameters and set their values
cmd.Parameters.Add("@title", SqlDbType.NVarChar, 100).Value = TextBox1.Text.Trim();
cmd.Parameters.Add("@datee", SqlDbType.DateTime).Value = DateTime.Now;
cmd.Parameters.Add("@post", SqlDbType.NVarChar, 100).Value = TextBox2.Text.Trim();
cmd.Parameters.Add("@cat", SqlDbType.NVarChar, 100).Value = DropDownList1.SelectedItem.Text.Trim();
cmd.Parameters.Add("@imageurl", SqlDbType.NVarChar, 250).Value = path;
// open connection, execute query, close connection
conn.Open();
int rowsInserted = cmd.ExecuteNonQuery();
conn.Close();
}
How to use 'LIKE' statement with unicode strings?
Make sure the collation on your table supports unicode.
using unicode text in sql server 2008
Try
declare @unicodetext nvarchar(250)
set @unicodetext = N'बन्द'
select @unicodetext
Maybe you noticed that SQL Server uses N
to any quoted string input when generating DDL scripts for you.
Related Topics
Sql: Using Null Values VS. Default Values
Group Datetime into 5,15,30 and 60 Minute Intervals
How to Get Last Day of Last Week in SQL
Spark Replacement for Exists and In
How to Combine Aggregate Functions in MySQL
Selecting Column Names That Have Specified Value
MySQL 'Create Schema' and 'Create Database' - Is There Any Difference
Warning: Null Value Is Eliminated by an Aggregate or Other Set Operation in Aqua Data Studio
Difference Between "And" and "Where" in Joins
Retrieve Column Names and Types of a Stored Procedure
Repeat Rows N Times According to Column Value
Optional Arguments in Where Clause
Hive - Unpivot Functionality in Hive
Extbase - Get Created SQL from Query
SQL Server Query Time Out Depending on Where Clause
Why Is a Primary-Foreign Key Relation Required When We Can Join Without It
T-Sql: Using a Case in an Update Statement to Update Certain Columns Depending on a Condition