目前我正在为学校做一个项目,但我无法解决这个问题。
我有一个表格,如果您向其中插入英文字符,它可以正常工作并且信息被插入到数据库中,但是如果我插入希伯来字符(@form),什么也不会发生。
现在,澄清一下,我已经测试了 100%,即使我插入希伯来字符,它也会进入包含 sql 插入的“if”块。
整个项目由 Visual Studio Web Developer 2008 管理。
如果我手动插入希伯来语写入值,数据库能够存储它们并输出,但是当尝试更新这些单元格(@form)时,希伯来语中的所有字符都会变成问号。
谁能帮我?我真的很感激。
谢了,兄弟们
编辑:
这是我的插入查询:(错误是一个List<string>
,接下来是 MyAdoHelper.cs)
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:
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();
}
}