我想要的是:我想输入作者id,但我只知道作者的名字来自表格作者。那么,在下面的查询中,如何获取作者id??
INSERT INTO book (title, isbn, author_id) VALUES('" + BookTitle.Text.ToString() + "', '" + BookIsbn.Text.ToString() + "', '(SELECT id FROM author WHERE first_name = '" + BookAuthor.Text.ToString() + "')')";
错误:
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 'Marijn')')' at line 1
我希望我说清楚我想要什么。
谢谢您!
最佳答案
Here you have to have function fn_getID(fname) which will return id.
"INSERT INTO book (title, isbn, author_id)
VALUES('" + BookTitle.Text.ToString() + "', '" + BookIsbn.Text.ToString() + "'"+fn_getID(BookAuthor.Text.ToString()))
关于c# - 奇怪的查询。从另一个表获取ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12596920/