How to display Urdu Unicode characters on my Windows Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shahhussain305
    New Member
    • Aug 2012
    • 4

    How to display Urdu Unicode characters on my Windows Forms

    Hay, I tried to get the Urdu Fonts from MySql Database using C# in Visual Studio 2010 in Windows Forms Application. When I get the value from table into my variable it shows the characters in ???? symbols. wherein PHP it is working very good without any problem.
    But in PHP i have used the following code:
    Code:
    <?php 
    	class CRUD {
    		var $con; 
    		//function to make connection to database
    		function connect(){
    			$this->con = mysql_connect("localhost","root","password") or die(mysql_error());			
    			[B]mysql_query("SET character_set_results=utf8", $this->con);
    			mb_language('uni');
    			mb_internal_encoding('UTF-8');
    			mysql_select_db("database1",$this->con);
    			mysql_query("set names 'utf8'",$this->con);[/B]				
    			}
                    //function to get the field value from the table specified in the query
    		function getValue($sql,$value){
    			$this->connect();
    			$result = mysql_query($sql,$this->con);
    			if(mysql_num_rows($result) > 0) {
    				$row = mysql_fetch_array($result);
    					$value = $row[$value];
    				}
    			else {
    					$value = "";
    				}
    				return $value;
    			}
                        ?>
    Now I do not know how to insert this line of code to my query in C#:

    Code:
    mysql_query("SET character_set_results=utf8", $this->con);
    			mb_language('uni');
    			mb_internal_encoding('UTF-8');
    			mysql_select_db("database1",$this->con);
    			mysql_query("set names 'utf8'",$this->con);
    I am using the following code in my C# class:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Sql;
    using System.Data.Odbc;
    using System.Data;
    using System.Windows.Forms;
    
    namespace Madrasa_Mgt.classes
    {
        class CRUD
        {
            private static string userid;
            private static string userkey;
            private OdbcConnection con;
            private OdbcDataReader odr;
            private OdbcCommand cmd;
            public bool flag;
            UTF8Encoding utf8 = new UTF8Encoding();
    
    
            public CRUD() {
                //connectToDb();
                setVars();
                
            }
            
        private OdbcConnection connectToDb(){
            try {
                con = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; uid=root; password=thefire; Server=localhost; Option=16834; Database=madrasa_jamia");
                if (con.State == ConnectionState.Closed) {
                    con.Open();
                }
            }
            catch (Exception exc) {
                this.msgErrorEx(exc);   
            }
            return con;
        }
    
        private void setVars() {
            try {
                this.connectToDb();
                string sql = "SELECT mad_name,mad_addr,phone,banner_photo,owner_name,licence_number,purchase_date,vendor_name,vendor_addr,vendor_phone,is_ok FROM configuration";
                cmd = new OdbcCommand(sql, this.con);
                cmd.ExecuteNonQuery();
                odr = cmd.ExecuteReader();
                if (odr.Read())
                {
                   GlobalVars.MadName = odr["mad_name"];
                   GlobalVars.MadrasaAddress = odr["mad_addr"];
                   GlobalVars.Phone = odr["phone"];
                   GlobalVars.Banner = odr["banner_photo"];
                   GlobalVars.OwnerName = odr["owner_name"];
                   GlobalVars.LicenseNumber = odr["licence_number"];
                   GlobalVars.PurchasedDate = odr["purchase_date"];
                   GlobalVars.VendorName = odr["vendor_name"];
                   GlobalVars.VendorAddress = odr["vendor_addr"];
                   GlobalVars.VendorPhone = odr["vendor_phone"];
                   GlobalVars.IsOk = odr["is_ok"];
                }
            }
            catch (Exception exc) { 
            }
        }
    and I am getting the following error message:
    class System.String
    Represents text as a series of Unicode characters.
    Error:
    Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)


    Please help me in this regards. Thanks in advance.
    Shah Hussain
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    I just came across your question, and realised I had a bookmark that may be really relevant here:

    Ever wonder about that mysterious Content-Type tag? You know, the one you’re supposed to put in HTML and you never quite know what it should be? Did you ever get an email from your friends in…


    It's an old article, but hopefully it'll prove of some use to you. All the best!

    Aimee.

    Comment

    • ariful alam
      New Member
      • Jan 2011
      • 185

      #3
      You are showing your data from MySql to any text box or control of your Visul Studio 2010 windows application. the controls font are a ASCII font by default. try by changing those controls font to a Unicode font. It may work.

      Hope it's help you. :)

      Comment

      • shahhussain305
        New Member
        • Aug 2012
        • 4

        #4
        hay, Ariful Alam and Aimee bailey first of all let me say you thanks for reply. but before going forth, let me say that i have resolved by updating my installed driver for MySQL, actually i was using MySQL driver version 3.x which was not support to send and or retrieve data as in Unicode format from MySQL databse. when i update MySQL driver and then run the application it works nicely and now its working without any problem.
        Thanks and regard.
        Shah Hussain

        Comment

        Working...