0

好的,这是我尝试过的代码片段:

    private static void CheckForChanges(MySqlConnection connection)
    {
        DateTime hair = DateTime.Parse(SmartStyleDataset.Tables["Hair"].Compute("MAX(lastUpdated)", null).ToString());
        DateTime cloths = DateTime.Parse(SmartStyleDataset.Tables["Cloths"].Compute("MAX(lastUpdated)", null).ToString());
        DateTime accessories = DateTime.Parse(SmartStyleDataset.Tables["Accessories"].Compute("MAX(lastUpdated)", null).ToString());
        DateTime cosmetics = DateTime.Parse(SmartStyleDataset.Tables["Cosmetics"].Compute("MAX(lastUpdated)", null).ToString());

        List<String>[] NewRows = { new List<String>(), new List<String>(), new List<String>(), new List<String>() };   

        using (var command = connection.CreateCommand())
        {
            connection.Open();
            command.CommandText = 
                 "SELECT * "
                + "FROM smartstyle.table_changes_logger "
                + "WHERE  Updated > @accessories AND Table = 'accessories' ; "
                + "SELECT * "
                + "FROM smartstyle.table_changes_logger "
                + "WHERE  Updated > @cosmetics AND Table = 'cosmetics' ; "
                + "SELECT * "
                + "FROM smartstyle.table_changes_logger "
                + "WHERE  Updated > @cloths AND Table = 'cloths' ; "
                + "SELECT * "
                + "FROM smartstyle.table_changes_logger "
                + "WHERE  Updated > @hair AND Table = 'hair'";

            command.Parameters.Add("@cloths", MySql.Data.MySqlClient.MySqlDbType.Timestamp).Value = cloths.ToString("yyyy-MM-dd HH:mm:ss");
            command.Parameters.Add("@hair", MySql.Data.MySqlClient.MySqlDbType.Timestamp).Value = hair.ToString("yyyy-MM-dd HH:mm:ss");
            command.Parameters.Add("@accessories", MySql.Data.MySqlClient.MySqlDbType.Timestamp).Value = accessories.ToString("yyyy-MM-dd HH:mm:ss");
            command.Parameters.Add("@cosmetics", MySql.Data.MySqlClient.MySqlDbType.Timestamp).Value = cosmetics.ToString("yyyy-MM-dd HH:mm:ss");

            using (var reader = command.ExecuteReader())
            {
                do
                {
                    while (reader.Read())
                    {
                        NewRows[0].Add(reader.GetString(1));
                        NewRows[1].Add(reader.GetString(2));
                        NewRows[2].Add(reader.GetString(3));
                        NewRows[3].Add(reader.GetString(4));
                    }

                } while (reader.NextResult());

            }
        }
 }

但这不起作用我从 mysql 收到以下一般错误我不明白 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'Table = 'accessories' 附近使用的正确语法;SELECT * FROM smartstyle.table_changes_logger WHERE Upd' 在第 1 行

4

1 回答 1

1

您需要像使用反引号一样转义MySQL 中的保留字。table

SELECT * 
FROM smartstyle.table_changes_logger 
WHERE  Updated > @accessories 
AND `Table` = 'accessories'
于 2013-08-07T10:41:15.563 回答