Currently I'm working on a project for school, and I can't solve this.
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.
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.
The whole project is managed with Visual Studio Web Developer 2008.
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.
Thanks, Guy
EDIT:
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:
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();
}
}
If you use microsoft sql server, try something like this.
And make also sure, that you use
nvarchar
i thinks ,you used the nvarchars for hebrew-characters field in your DB...