MySQL:子查询返回超过1行

时间:2014-05-08 17:04:22

标签: mysql sql

我有一个带有SELECT_LAST_ID的Insert查询,执行时我得到一个错误,说子查询返回超过1行。这是查询:

INSERT INTO categoriesshares (categoryId, userPosted, shareText, isPic, shareTime, isSub) 
VALUES (@categoryId,@userPosted,@shareText, @isPic, @shareTime, @isSub); 
SELECT LAST_INSERT_ID();

以下是完整代码:

MySqlConnection con = new MySqlConnection(connString);
                con.Open();
                MySqlCommand com = con.CreateCommand();
                com.CommandText = "INSERT INTO categoriesshares (categoryId, userPosted, shareText, isPic, shareTime, isSub) " +
                          "VALUES (@categoryId,@userPosted,@shareText, @isPic, @shareTime, @isSub); SELECT LAST_INSERT_ID()";
                com.Parameters.AddWithValue("@categoryId", (isSub) ? Convert.ToInt32(Request.Params["subcat"]) : Convert.ToInt32(Request.Params["cat"]));
                com.Parameters.AddWithValue("@userPosted", User.Identity.Name);
                com.Parameters.AddWithValue("@shareText", shareText);
                com.Parameters.AddWithValue("@isPic", false);
                com.Parameters.AddWithValue("@shareTime", shareTime);
                com.Parameters.AddWithValue("@isSub", isSub);

                int newItemId = Convert.ToInt32(com.ExecuteScalar());
                con.Close();

可能是什么问题?

0 个答案:

没有答案
相关问题