I have a SQLCommand :
"Update Customers Set Name = @name where code = @code"
and this code:
cmd.Parameters[0].Value = "بهروز";//(some Unicode characters)
cmd.Parameters[1].Value = 1;
cmd.ExecuteNonQuery();
or this code:
UpdateCommand.CommandText = "UPDATE [Customers] SET [Name] = @p1 WHERE (([Code] = @p2) AND ((@p3 = 1 AND [Name] IS NULL) OR ([Name] = @p4)))";
UpdateCommand.Parameters.Add("@p1", System.Data.SqlDbType.SmallInt, 0, "Name");
UpdateCommand.Parameters.Add("@p2", System.Data.SqlDbType.NVarChar, 0, "Code");
UpdateCommand.Parameters.Add("@p3", System.Data.SqlDbType.NText, 0, "Name");
UpdateCommand.Parameters.Add("@p4", System.Data.SqlDbType.SmallInt, 0, "Name");
and when I Select Customers Table I have lots of "?"s.
why does SQLCommand work Correct when working with a SQLDataAdapter?
How can i convert my Unicode Data to ANSI?
edit:
in other words :
what code does SQLDataAdapter use?
anyone has the source code of that part of .net framework?
Dear Behrooz just use a simple SQL command
N'ناصر حاجلو'
whenever you use N you forcesql to use unicode and nothing will corrept.
All strings in .NET are Unicode. There is no such thing as an ANSI string within .NET. If you want a string encoded into a byte array as ANSI, use Encoding.GetBytes.
Your issue may be with the way its sending data to the stored procedure. I think you need to add the sql datatype to the parameter. Try the following code:
cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 30);
See the SqlParameterCollection.Add Method for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With