I am trying to insert square root symbol √ into my SQL Server database from an ASP.NET page. The radical symbol (√) gets inserted as letter v instead.
Where could I be going wrong?
Thanks for your assistance.
Your database column type should be nVarChar to insert Unicode characters.
Also you need to pass values like below:
cmd.Parameters.Add("#ColumnName", SqlDbType.NVarChar, 1024).Value = txtName.Text;
Column in your table should be able to store unicode characters, try change the type to nvarchar
and while inserting you should use N symbol before the value
let say the column name is square_root and table is test
insert into test(square_root) values(N'√25 = 5')
Am using SQLCommand to make an insert query like following:
db.Database.SQLCommand("sql statement" , "pars");
but when i type Arabic (Unicode) text into the SQL statement it's only shows question marks in the database.
and when i do it as a database query in SQL Server management studio it works fine! please help
You need to set the collation for you database to be arabic, and also that of the table column.
Also make sure the column is NVARCHAR and not VARCHAR
I have a column in table with text datatype and trying to save some string value to this column from C# code. Issue comes when I use some very large string.
I am not able to save more than 43679 character into text field. I know text size can be 2^31.
I also tried saving same value from SSMS and noticed same scenario.
There is nothing special about code, but still SQL query is given below...
update TableName
set ColumnName = 'some text more than 43679 char'
where id=<some int id>
just to mention... column is declare in table as
[columnname] [text] NULL
Can anyone tell me what could be wrong.
You can try to use varchar(max) to store huge amount of data. See MSDN
We recommend that you store large data by using the varchar(max),
nvarchar(max), or varbinary(max) data types. To control in-row and
out-of-row behavior of these data types, use the large value types out
of row option.
You can also check the same issue here: SSMS - Can not paste more than 43679 characters from a column in Grid Mode
My company use sql server 2000 to store data . There is a table with a column named 'Vattu' .
The problem is that : this column declare as varchar data type , however it's save both unicode and anscii value !
So every time I show this column data on web , it show unreadable characters.
Is there any way to convert data to unicode value using c# ?
A quick google search would have given you the answer. Anyway you use System.Text.Encoding to encode the ascii to unicode. check the sample code at Encoding.Convert Method
Also converting the column datatype to NVarchar will be better in long run. Doing so you will save CPU processing that you will be using due to conversion at c# level.
You need to change the data type of the column to nvarchar in order to store Unicode data.
The Unicode data you've already tried to store in the column is gone - you can't magically get it back, unless your application logged the data or you were running traces of all commands and still have access to those.
I'm using the C# .NET Mysql Connector, and when running this query:
INSERT INTO convos (`userid`,`time`,`from`,`content`,`read`,`deleted`, `ip`, `source`, `charname`, `to`) VALUES ('3', '1347396787', 'Chára', '........', '0', '0', '0.0.0.0:0000', 'C', 'óóóíííí', 'óóóíííí');
I get the following error:
Incorrect string value: '\xE1ra' for column 'from' at row 1
I understand my encoding, everything was configured for utf8, utf8_general_ci. Database, table and columns are configured for utf8. The data is sent from the client in utf8.
If i use a 3rd party tool like, Workbench to insert the query or use the mysql command line it works fine. I don't know if there is a bug with the connector or i need to be doing something else with the values before insert?
Any idea?
Thanks
Is there any in mysql to covert to the correct type?
I believe you need to alter the column's char set:
use below code for those columns which is using UTF-8.
ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255)
CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
Unicode string prefix with N
First see your table convos and make sure columns data types is either one of nchar, nvarchar and You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server
Tyr:
insertQuery = "INSERT INTO convos (`userid`,`time`,`from`,`content`,`read`,`deleted`, `ip`, `source`, `charname`, `to`) VALUES
(N'3', N'1347396787', N'Chára', N'........', N'0', N'0', N'0.0.0.0:0000', N'C', N'óóóíííí', N'óóóíííí')";
I figured this out, its taken a while but it seems i was setting the charset too often. The database, tables, columns are all in UTF8. When i made a connection i had "CHARSET=UTF8" in the connection string. I was also running "SET NAMES 'utf8' COLLATE 'utf8_general_ci'" everytime i made a connection. I dropped the CHARSET=UTF8 and "SET NAMES 'utf8' COLLATE 'utf8_general_ci'" and its all working now.
Update it
INSERT INTO convos (`userid`,`time`,`from`,`content`,`read`,`deleted`, `ip`, `source`, `charname`, `to`) VALUES ('3', '1347396787', 'Chara', '........', '0', '0', '0.0.0.0:0000', 'C', 'óóóíííí', 'óóóíííí');
I think for "chara"in your 3rd value gives it
For someone who has tried all the suggestions, and nothing has worked (like myself), it is worth checking what MySQL types are your fields mapped to in C#. My text fields were automatically mapped as MySqlDbType.Blob and that was causing the error. I changed the type to MySqlDbType.Text, and I don't see the error any more.
Here is my original response to a similar thread:
https://stackoverflow.com/a/16989466/2199026
config mysql like below. it will solve the unicode error when insert into mysql from java or C#
enter image description here