When words_array[i]
is Hebrew text, the database shows '?????'
in place of the word.
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (@word);
myCommand.Parameters.Add(new SqlParameter("@word", SqlDbType.Varchar, 50));
command.Parameters["@word"].Value = words_array[i];
I tried below, but got an error :
Incorrect syntax near 'N'
My attempt:
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (N'@word'N);
I tried this, too - problem: placed the text '@word' in place of the Hebrew word.
myCommand.CommandText = "INSERT INTO MyTable(word) VALUES (N'@word');
Change SqlDbType.VarChar
with SqlDbType.NVarChar
. There's no need to prefix strings when using parameterized queries.
The line :
myCommand.Parameters.Add(new SqlParameter("@word",SqlDbType.VarChar,50));
Says that the parameter's type is a string using a single-byte codepage instead of a Unicode string. Strings in .NET are Unicode but this line tells the driver to convert the value to a single-byte encoding using the codepage specified by the thread's CurrentCultureInfo
.
It should be
myCommand.Parameters.Add(new SqlParameter("@word",SqlDbType.NVarChar,50));
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.