C#ASP.NET(VS 2008 Exp)数据库将UPDATE中的希伯来语值保存为'?' [英] C# ASP.NET (VS 2008 Exp) Database saves hebrew value from UPDATE as '?'

查看:117
本文介绍了C#ASP.NET(VS 2008 Exp)数据库将UPDATE中的希伯来语值保存为'?'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我没有找到我以前的问题的解决方案(链接),我发布一个新的,希望一个解决方案。对不起,如果我违反规则,但我没有收到解决方案。

As I haven't found a solution to my previous question (Link), I am posting a new one, hoping for a solution. I'm sorry if I am breaking the rules, but I haven't received a solution.

当我尝试更新一行,我跟踪了什么查询发送,例如:

when I try to update a row, and I have tracked what query is sent, for example:

UPDATE global_status SET title = 'Login_Failure', info = 'שדכ' WHERE id = '2'

所以你可以看到发送的最后一个查询是希伯来语, 。我以这种方式执行:

So you can see that the final query which is sent is in Hebrew, so it's not a problem before that. I execute it this way:

string Status_Update = "UPDATE global_status SET title = '" + Title + "', info = '" + Info + "' WHERE id = '" + Request.Form["Status_Key"] + "'";

MyAdoHelper.DoQuery(GlobalVar.DatabaseName, Status_Update);

方法:

public static void DoQuery(string fileName, string sql)
{
    SqlConnection conn = ConnectToDb(fileName);
    conn.Open();
    SqlCommand com = new SqlCommand(sql, conn);
    com.ExecuteNonQuery();
    com.Dispose();
    conn.Close();
}

更新后,数据库包含???

After the update, the database contains ??? where I inserted Hebrew letters.

我可以手动将希伯来语值插入到数据库中,也可以将它们返回。

I can manually insert Hebrew values into the database, and also get them back.

我有另一种形式(注册),其中我能够使用DoQuery()插入希伯来语值;

I have another form (registration) where I am able to insert Hebrew values, using the DoQuery();

这是更新页面的源代码更新记录的标题和信息,没有什么特别):

Here is the source code for the update page (it's updating a title and info of a record, nothing special):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_EditGlobalStatus : System.Web.UI.Page
{
    public string StatusesTable;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["Status_Update"] != null)
        {
            string Title = Request.Form["Status_Title"].Secure();
            string Info = Request.Form["Status_Info"].Secure();

            Info = Info.Replace("/s", "<span class\"res\">").Replace("/e", "</span>");

            string Status_Update = "UPDATE global_status SET title = '" + Title + "', info = '" + Info + "' WHERE id = '" + Request.Form["Status_Key"] + "'";

            MyAdoHelper.DoQuery(GlobalVar.DatabaseName, Status_Update);
        }

        if (Request.Form["Status_Delete"] != null)
        {
            string Status_Delete = "DELETE FROM global_status WHERE id = '" + Request.Form["Status_Key"] + "'";
            MyAdoHelper.DoQuery(GlobalVar.DatabaseName, Status_Delete);
        }

        string GetGlobalStatuses = "SELECT * FROM global_status";
        DataTable dt = MyAdoHelper.ExecuteDataTable(GlobalVar.DatabaseName, GetGlobalStatuses);

        if (dt.Rows.Count > 0)
        {
            StatusesTable = "<table cellspacing=\"15\">";

            StatusesTable += "<th>כותרת ההודעה</th><th>מידע ההודעה</th>";

            foreach (DataRow status in dt.Rows)
            {
                StatusesTable += "<tr><form method=\"post\" action=\"\">";

                StatusesTable += "<input type=\"hidden\" name=\"Status_Key\" value=\"" + status["id"].ToString() + "\" />";
                StatusesTable += "<td><input size=\"25\" dir=\"ltr\" type=\"text\" name=\"Status_Title\" value=\"" + status["title"].ToString() + "\" /></td>";
                StatusesTable += "<td><input size=\"90\" type=\"text\" name=\"Status_Info\" value=\"" + status["info"].ToString().Secure() + "\" /></td>";

                StatusesTable += "<td><input type=\"submit\" name=\"Status_Update\" value=\"עדכן\"><input type=\"submit\" name=\"Status_Delete\" value=\"מחק\"></td></form></tr>\r\n";
            }

            StatusesTable += "</table>";
        }
        else
        {
            StatusesTable = "<h1>אין משתמשים קיימים</h1>";
        }
    }
}

Guy

推荐答案

很多人都能够解决这个问题在字符串的开头像这样

After reading several text explanation I wound that many people are capable to solve the problem with N at the beginning of string like this

 string Status_Update = "UPDATE global_status SET  title = '" +
 Title + "', info =N'" + Info + "'  WHERE id = '" +
 Request.Form["Status_Key"] + "'";

也请务必尝试nvarchar或unicode

also make sure to try nvarchar or unicode

这篇关于C#ASP.NET(VS 2008 Exp)数据库将UPDATE中的希伯来语值保存为'?'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆