0

我已经创建了一个 web 服务和一些 web 方法,我在我的 android 应用程序中调用了 ksoap 工作。其中一种方法获取波斯语字符串并将其插入数据库,但是当我退出并检查时,我只看到问号(?)而不是波斯语字符。

带有 ksoap 的我的 android 应用程序中的 Web 服务调用方方法

        public String sendcomment(String Comment , Float rate)

          {

            String MethodName="SetResComment";
            try {
                SOAP_ACTION = namespace + MethodName;

                //Adding values to request object
                request = new SoapObject(namespace, MethodName);
                //Adding string value to request object
                PropertyInfo P_RSID =new PropertyInfo();
                P_RSID.setName("RSID");
                P_RSID.setValue(staticvar.CurrentRes.getID()); //llllllllll
                P_RSID.setType(String.class);
                request.addProperty(P_RSID);

                PropertyInfo P_UID =new PropertyInfo();
                P_UID.setName("UID");
                P_UID.setValue(staticvar.UID); //llllllllll
                P_UID.setType(String.class);
                request.addProperty(P_UID);

                PropertyInfo P_Name =new PropertyInfo();
                P_Name.setName("Name");
                P_Name.setValue(staticvar.Mame); //llllllllll
                P_Name.setType(String.class);
                request.addProperty(P_Name);

                PropertyInfo P_Comment =new PropertyInfo();
                P_Comment.setName("Comment");
                P_Comment.setValue(Comment); //llllllllll
                P_Comment.setType(String.class);
                request.addProperty(P_Comment);

                PropertyInfo P_Rate =new PropertyInfo();
                P_Rate.setName("Rate");
                P_Rate.setValue(String.valueOf(rate)); //llllllllll
                P_Rate.setType(String.class);
                request.addProperty(P_Rate);




                SetEnvelope();

                try {

                    //SOAP calling webservice
                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    //Got Webservice response
                    String result = envelope.getResponse().toString();

                    return result;

                } catch (Exception e) {
                    // TODO: handle exception
                    return e.toString();
                }
            } catch (Exception e) {
                // TODO: handle exception
                return e.toString();
            }
          }

我的网络方法:

[WebMethod]
    public string SetResComment(string RSID, string UID, string Name, string Comment, string Rate)
    {
        float rt = float.Parse(Rate);
        PayamDB pdb = new PayamDB();
        return pdb.SetResComment(RSID, UID, Name, Comment, rt);
    }

payamDB 类中的 setrescomment 方法

public string SetResComment(string RSID,string UID, string Name, string Comment,float Rate)
    {
        try
        {

            SqlCommand command;

            {
                command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "','" + Name + "' , '" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);
                command.Connection.Open();
                int s=command.ExecuteNonQuery();
                command.Connection.Close();
                return s.ToString();
            }


        }
        catch (Exception e) { return "error:"+e.Message; }
    }
4

2 回答 2

0

要在 Windows 机器上查看,请下载波斯语字体。安卓也是如此。你是一个问号,因为你的系统不知道那是什么类型的语言或字体。

于 2014-07-22T22:38:02.033 回答
0

终于找到了我的答案

我们应该N在插入查询中使用 UTF-8 编码的 before 值

像这样 :

command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "', N'" + Name + "' , N'" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);
于 2014-07-24T09:34:22.690 回答