John John - 1 year ago 109
SQL Question Question Marks instead of Arabic text

I am using

Visual studio 2015
, and

I've two issues:

  1. In inserting Arabic data into the database (MYSQL workbench), it
    appears question marks
    I found solution asked me to change
    the type of data from varchar to nvarchar then add capital
    Arabic string (
    INSERT INTO TableName (ColumnName) values(N’ArabicText’)
    ) How can I apply that in this code? I tried to add
    different place but it did not work?

  2. When I determine the type of data as

    workbench, the program appear message :
    change applied successfully
    however when I open the table I found
    returned again.

    string query = "UPDATE learningobjects SET level=?level, subjectName=? subjectName WHERE ID=?ID";
    using (MySqlCommand cmd = new MySqlCommand(query, cn))
    cmd.CommandText = query;
    cmd.Parameters.AddWithValue("?level", Level);
    cmd.Parameters.AddWithValue("?ID", lblid.Text);

    cmd.Parameters.AddWithValue("?subjectName", txtsubject.Text);

Answer Source

MySQL is not SQL Server, so the solutions are a little different but the cause of the question marks is the same. What you are seeing is a character conversion error which can happen in any point in your request/response chain.

Microsoft SQL Server introduced NCHAR, NVARCHAR, and NTEXT to handle unicode. These are all Microsoft specific keywords so they won't work with MySQL. These days, MySQL should be set up to handle unicode character sets by default, but just in case you may want to check out these links:

And to be safe, make sure your connection string specifies the character set (should be OK if the rest of MySQL is set up for UTF)

Lastly, something else that should not be overlooked, is your forms need to be UTF compliant as well. (ref)

<form action="demo_form" accept-charset="utf-8">

Which can also be specified like this with ASP.NET MVC:

@using (Html.BeginForm(null, null, FormMethod.Post, new { accept_charset = "utf-8" })) {
  <!-- content of form -->

I would start with how data gets in to your database, and then see what happens with the data after you put it in.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download