Urdu message sent from sql to mobile handset, is i

2019-07-21 01:51发布

问题:

I am assigning Urdu text to a variable in c# and inserting it into database (SendMessages table), it saves Urdu message perfectly without any modification, great but when that message is received in any mobile handset then it appears as ??????????????????????, why ? i checked it with all urdu compatible handsets which receive other urdu messages perfectly but not this one.

Code asp.net:

String MessageLanguage= Convert.ToString(ViewState["LanguageCode"]); //

                        if (MessageLanguage == "ur")
                        {
                            String UrduMsg = ComplaintCode +" "+"اپکی سثیکایت درج کردی گیؑ ھے۔ سثیکایت کوڈ یہ ہے";
                            quebiz.Insert(lblContact.Text, UrduMsg, null, Convert.ToInt32(lblComplainantID.Text), null, null);
                            ViewState["LanguageCode"] = null;

                        }

In simple words, urdu message being passed from C# into sql table is fine and perfect, not problem but after receiving same sms in handset, it doesn't work that way.

why ? help ? I am using asp.net C#.net 4.0 with sql server 2014.

回答1:

According to your comments, you're using varchar to store the message in your database. However, varchar does not support Unicode, which means that anything that's not Latin characters (the characters used by English) does not show properly. Change that to nvarchar, which does support Unicode.



回答2:

An idea could be use varchar in your database and follow the steps

  1. Use base 64 to save the data into data base
  2. Use Encoding.UTF8 to get bytes and convert them to Base64
  3. When fetch data from database use Encoding.UTF8.GetString(Convert.FromBase64String("value") and use this value to display.