HTML/ASPX textbox to store non-english characters to SQL database - asp.net

I have this textbox on an .aspx page, which when submitted it stores whatever typed in the textbox into a nvarchar column in MS SQL 2005.
It works fine, until you try putting chinese characters.
These characters are converted to question marks (?) in the database.
How do you store non-english characters from a <input type="text"> to database?

The main thing would be to ensure that every step of the pipeline supports international characters; i.e. - at what point do you first see "?" ? In the aspx code? Or only once it gets into the database table?
The web page should already be using an encoding such as UTF8, so that should be OK - but what data type are you using at the database? It would need to be nchar/nvarchar(n)/nvarchar(max) (or ntext on older versions of SQL Server).

Related

asp.net turkish character issue

I have a Turkish character problem. If my search string contains "İ", it doesnt return the existing data. When I do select statement below in MSSQL TOOL, It works but when I call the same select statement in ASP.NET , it doesnt work.
here is the select
select * from product where name like N'%GALVANİZ%'
this works in mssql tool and returns the expected data rows. but it doesnt return any data when called in asp.net
how can I get it to return data in asp.net ?
If you're using Turkish characters make sure that your column is nchar or nvarchar.
Then if you're having problems fetching it at the asp.net side try to change it's encoding to "windows-1254" with Encoding.GetEncoding("windows-1254")

How to get full value of a blob from sqlite

I'm using SQLite Administrator to query a blob in a table. I'm using a query that looks like this:
SELECT quote(data) FROM versions WHERE id = '....'
The blob is longer than 256 characters. When I look at the results, I'm only getting the first 256 characters back.
The blob contains XML. How do I query the database so I get the full XML back?
Tony
I ended up writing a quick WinForms application to retrieve the data from the database and put it into a TextBox control. Thanks anyway.

Oracle character set data is not being displayed in asp.net

I have stored data in the Oracle database 9i in the WE8MSWIN1252 characterset in URDU and now I want to display this data on browser with asp.net, but the data is not being displayed accurately it is displaying in chinese-like language.
Can anyone tell me how can translate this data into actual URDU form?
You cannot properly encode Urdu data in CHAR or VARCHAR2 data types if the database character set is Windows-1252. You can only encode the characters that are part of the Windows-1252 character set which is a Western European character set. You would need to either use NCHAR and NVARCHAR2 data types (assuming your national character set supports Urdu) or change the database character set of the database. There is a chapter in the Globalization Support Guide that discusses how to change the character set of an existing database.

Storing French (decimal values) in database?

I have my form set in french as well, and it automatically changes the text format to use ','. However When I try to insert my values into the database it says cannot convert nvarchar to decimal?
Worst case, Is there a way I can disable the numbers from changing to use ',' and just use '.' always regardless what language it is?
My working language is vb.net
Thanks,
Robert
If you're passing the values down to the database as nvarchar then you'll need to have converted this to a string using yourDecimalValue.ToString(Globalization.CultureInfo.InvariantCulture) or similar. SQL Server will always expect a decimal to be in 1.23 format - you can imagine the trouble that would result if queries including WHERE myvalue IN (1,25, 1,33, 1,45) were submitted!

Classic ASP, SQL Server and character encodings

I have a classic ASP page that gets POSTed to. The data gets POSTed as UTF-8 (I can see this in Fiddler). I then open an ADODB connection to a database and store the data in a VARCHAR field. If the data can be represented by 8859-1 (e.g. iñtërnâtiônàlizætiøn) it is stored correctly in the varchar field. If I try strings that can't be mapped to 8859 (e.g. Здравствуйте!) I get ????????????!. This all makes sense as the varchar field cannot hold unicode. I also understand the using an nvarchar field should enable me to store utf-8 strings.
My question is this. What settings in SQL Server or in the ADODB object control how the strings are converted from UTF-8 to 8859-1? Does VBScript (ASP) send the strings to ADODB.Connection.Execute as UTF-8 (or what I think it is actually doing - UTF-16) and the database itself handles the conversion? Is this controlled by the collation of the database (SQL_Latin1_General_CP1_CI_AS in this case)?
If you switch to using NVARCHAR instead then you'll need to remember to use the N specifier in your SQL commands like so whenever you use a string which is Unicode
INSERT INTO SOME_TABLE (someField) VALUES (N'Some Unicode Text')
SELECT * FROM SOME_TABLE WHERE someField=N'Some Unicode Text'
If you don't do this then the strings won't get treated as Unicode and your data will be silently converted to Latin1 or whatever the default character set for the relevant database/table/field even if that field is a NVARCHAR
You are correct.
VBScript and ADODB only know strings as Unicode (or UTF-16 as its sometimes refered to).
Its part of the DBs collation settings that determine how the VARCHAR fields are encoded.
In SQL_Latin1_General_CP1_CI_AS its really the CP1 bit which is determining the CodePage to use. In this case 1 is a legacy reference to Windows-1252 which is a superset of ISO-8859-1.

Resources