本文介绍了C#ASP.NET(VS 2008)DB忽略INSERT,如果它包含希伯来字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在为学校开展一个项目,我无法解决这个问题。

Currently I'm working on a project for school, and I can't solve this.

我有一个表格,如果插入英文字符,它工作正常,信息插入到DB,但如果我插入希伯来字符(@form),没有任何反应。

I have a form, and if you insert to it English characters, it works fine and the info is inserted into the DB, but if I insert Hebrew characters (@form), nothing happens.

现在, 100%,即使我插入希伯来字符,它进入包含sql插入的'if'块。

Now, to clarify, I have tested 100%, that even when I insert Hebrew characters, it gets into the 'if' block which contains the sql insert.

整个项目由Visual Studio Web Developer 2008。

The whole project is managed with Visual Studio Web Developer 2008.

如果我手动插入希伯来语写入的值,数据库能够存储和输出,但是当尝试更新这些单元格(@form)希伯来语中的人物成为问号。

If I manually insert hebrew written values, the DB is able to store them, and output, but when trying to update those cells (@form), all the characters in Hebrew become question marks.

任何人都可以帮助我吗?非常感谢。

Can anyone help me? I would really appreciate it.

谢谢,Guy

编辑:

这是我的插入查询:(错误是列表< string> ,MyAdoHelper.cs接下来)

Here is my insertion query: (Errors is a List<string>, MyAdoHelper.cs comes next)

if (Errors.Count == 0)
{
      string Add_Member = "INSERT INTO members (name, password, email, gender, registration_date) VALUES ('" + Nickname + "', '" + Password + "', '" + Email + "', '" + Gender + "', '" + DateTime.Now.ToString() + "')";

      MyAdoHelper.DoQuery(GlobalVar.DatabaseName, Add_Member);

      Errors.Add(GlobalVar.GlobalStatus["Register_Success"]);
}

MyAdoHelper.cs:

MyAdoHelper.cs:

public class MyAdoHelper
{
    public MyAdoHelper()
    {
    }

    public static SqlConnection ConnectToDb(string fileName)
    {
        string path = @"C:\Users\Guy\Desktop\Project\App_Data\";
        path += fileName;
        string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
                             path +
                             ";Integrated Security=True;User Instance=True";
        SqlConnection conn = new SqlConnection(connString);
        return conn;
    }

    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();
    }

    public static int RowsAffected(string fileName, string sql)       
    {
        SqlConnection conn = ConnectToDb(fileName);
        conn.Open();
        SqlCommand com = new SqlCommand(sql, conn);
        int rowsA = com.ExecuteNonQuery();
        conn.Close();
        return rowsA;
    }

    public static bool IsExist(string fileName, string sql)
    {
        SqlConnection conn = ConnectToDb(fileName);
        conn.Open();
        SqlCommand com = new SqlCommand(sql, conn);
        SqlDataReader data = com.ExecuteReader();
        bool found;
        found = (bool)data.Read();

        conn.Close();
        return found;
    }

    public static DataTable ExecuteDataTable(string fileName, string sql)
    {
        SqlConnection conn = ConnectToDb(fileName);
        conn.Open();
        SqlDataAdapter tableAdapter = new SqlDataAdapter(sql, conn);
        DataTable dt = new DataTable();
        tableAdapter.Fill(dt);
        return dt;
    }

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

    public static int CountTableRows(string TableName)
    {
        SqlConnection Conn = MyAdoHelper.ConnectToDb(GlobalVar.DatabaseName);
        Conn.Open();
        string TotalRows = "SELECT COUNT(*) FROM " + TableName;
        SqlCommand Cmd = new SqlCommand(TotalRows, Conn);
        return (int)Cmd.ExecuteScalar();
    }
}


推荐答案

你使用microsoft的sql server,尝试这样的东西。

If you use microsoft sql server, try something like this.

INSERT INTO tabelle (Spalte) VALUES (N'äüö');

并确保您使用 nvarchar

这篇关于C#ASP.NET(VS 2008)DB忽略INSERT,如果它包含希伯来字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:53