C #: Can't print data as Unicode characters from MYSQL database

Hi I have developed a Windows application that allows the user to save data and view data in tamil font. I installed the font "Bamini" (Tamil font) and set the textboxes and datagridview to the Bamini font. I can save and retrieve data in tamil.

The problem is that the tamil data I input is encoded and stored in the database eg: if I enter "இந்தியா" in a textbox and save it, it gets saved as ", e; j_ah" in mysql db (I set the column character set as utf8). Because of this, when I receive data and try to print it, instead of "இந்தியா" it prints ", e; j_ah".

Can anyone please let me know what I am doing wrong here?

The code I'm using to insert the line:

The value of textBox1 is 'இந்தியா' (because the font of the textbox is set to the font "Bamini" tamil)

     string insertdata = "INSERT INTO tamil (country) VALUES (@cnt)";
     MySqlCommand cmd = new MySqlCommand(insertdata,connection);
     connection.Open();
     cmd.Parameters.AddWithValue("@cnt",textBox1.Text);
     cmd.ExecuteNonQuery();
     connection.Close();

      

The database is affected as follows:

      tablename: Tamil
      Sno   Country
      1     ,e;j_ah

      

Table structure:

          CREATE TABLE `tamil` (                              
            `sno` int(11) auto_increment NOT NULL,                        
            `Description` varchar(50) NOT NULL,                          
            `Country` varchar(50) character set utf8 NOT NULL,                         
            KEY `id_sno` (`sno)                             
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ; 

      

+3


source to share


5 answers


After a long list of trials, I finally found an alternative solution for printing Tamil characters in my printer. Note. Hardware tech support informed me that many thermal printers do not accept Tamil characters that are sent via the Auxiliary Printer class.



So, I developed a crsytal report and tried printing, with immediate success. (My printer is a 3-inch thermal printer)

+1


source


Can anyone please let me know what I am doing wrong here?

You are using a visual coding font.

In this diagram, you press the comma key on your keyboard and enter the regular character U + 002C COMMA ,

. The text field is specified in a font where the shape of the comma makes it look like Tamil I, but it is still really a comma.



A comma will be stored in the database and search tools will match its comma; if you pull it out of the database and display it in Bamini font then it will look like Tamil I but display it in any standard font like the one you use to check your database and it will look like a comma ...

Visual coding fonts are how we used to deal with language scripts that don't have standard coding but shouldn't be used today - Bamini patron in the basket.

Modern operating systems supply native Tamil keyboard and font (eg under Windows, Nirmala UI). Using this approach, the user would type into a normal text box (which did not have a special set of fonts) and get the real Unicode character U + 0B87 Tamil letter i

, which should look the same in the database and behave semantically accordingly.

+2


source


There is something wrong with the UTF-8 encoded string. ", e; j_ah" is not the UTF-8 representation of your string. I recommend completely bypassing the UTF-8 feature of the database and using a simple BLOB for the Country column, which stores a simple variable length byte array. Then use UTF-8.NET codec and encrypt / decode yourself, storing the encoded byte array in the BLOB column.

So, change your Country declaration to:

`Country` BLOB NOT NULL,   

      

Use Encoding.UTF8.GetBytes () and Encoding.UTF8.GetString () to encode / decode your Tamil strings.

0


source


Put something like this in your connection string:

ID = my_user, password = my_password, base = some_db123, encoding = utf8;

And change Description

to CHARACTER SET utf8

(or utf8mb4).

See this for more debugging: fooobar.com/questions/26415 / ...

0


source


Basically, Bamini is not a Unicode standard. It has encodings of its own, so whenever you read you need to decode it, which means you need to set the bamini font to the content. the system does not install the bamini font when trying to print.

so the solution is to either use unicode fonts instead of bamini or install bamini font at print time. In the meantime, there is no need to know about it. ”

0


source







All Articles