Incorrect string value: '\xEF\xBF\xBD' for column

前端 未结 3 815
孤街浪徒
孤街浪徒 2020-12-03 08:09

I have a table I need to handle various characters. The characters include Ø, ® etc.

I have set my table to utf-8 as the default collation, all columns use table de

3条回答
  •  忘掉有多难
    2020-12-03 08:58

    Mattmanser is right, never write a sql query by concatenating the parameters directly in the query. An example of parametrized query is:

    string lastname = "Doe";
    double height = 6.1;
    DateTime date = new DateTime(1978,4,18);
    
    var connection = new MySqlConnection(connStr);
    
    try
    {
        connection.Open();
    
        var command = new MySqlCommand(
            "SELECT * FROM tblPerson WHERE LastName = @Name AND Height > @Height AND BirthDate < @BirthDate", connection);
    
        command.Parameters.AddWithValue("@Name", lastname);
        command.Parameters.AddWithValue("@Height", height);
        command.Parameters.AddWithValue("@Name", birthDate);
    
        MySqlDataReader reader = command.ExecuteReader();
        ...
    }
    finally
    {
        connection.Close();
    }
    

提交回复
热议问题