2011-04-22 153 views
1

爲什麼以下查詢在MySql上失敗?MySql INSERT失敗

NHibernate: INSERT INTO UserSetting (userId, key, value) VALUES (?p0, ?p1, ?p2); ?p0 = ccda78da-689d-4d86-ba72-d65eaf281edf [Type: Guid (0)], ?p1 = 'Hello' [Type: String (5)], ?p2 = 'World' [Type: String (5)]

有了這個錯誤:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, value) VALUES ('ccda78da-689d-4d86-ba72-d65eaf281edf', 'Hello', 'World')' at line 1"}

回答

4

key是一個保留字。

試試這個:

INSERT INTO UserSetting (userId, `key`, value) VALUES (?p0, ?p1, ?p2) 
+0

@webwise例如:不幸的是,我不熟悉'NHibernate'。最好避免對象名稱中的保留關鍵字。 – Quassnoi 2011-04-22 13:31:26