0

最近、基本的なフォーラム アセンブリをコンパイルしてテストしようとした後、驚くべき MySQL エラーに遭遇しました。

Forum.ForumException: MySql.Data.MySqlClient.MySqlException (0x80004005): 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 'desc) VALUES('bar', 'bar')' at line 1 at ...

Forum アセンブリの CreateBoard 関数を次に示します。

        public int CreateBoard(string bname, string bdesc)
        {
            MySqlConnection con = new MySqlConnection(conString);
            MySqlCommand cmd = new MySqlCommand("INSERT INTO boards (name, desc) VALUES(?name, ?desc)", con);
            int res_id = 0;

            try
            {
                //cmd.CommandText = "INSERT INTO boards(name, desc) VALUES(?name, ?desc)";
                cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value = bname;
                cmd.Parameters.Add("?desc", MySqlDbType.VarChar).Value = bdesc;
                con.Open();
                cmd.ExecuteNonQuery();
                //get the id of the new board
                //cmd.CommandText = "SELECT last_insert_id() FROM boards";
                //res_id = (int)cmd.ExecuteScalar();
                return res_id;
            }
            catch (Exception yf)
            {
                throw new ForumException(yf.ToString());
            }
            finally
            {
                con.Close();
            }
        }

最後に、テスト ページ「a.aspx」のコード スニペットを次に示します。

protected void Page_Load(object sender, EventArgs e)
{
    Forum f = new Forum();
    try
    {
        int b = f.CreateBoard("foo", "bar");
        if (b == 0)
        {
            Response.Write("Board creation failure :(");
            return;
        }
        Response.Write("Board create with id '" + b + "', name 'foo', and description 'bar'");
    }
    catch (ForumException ff)
    {
        Response.Write(ff.ToString());
    }
}

クエリが実行されると、ランダムな引用符がどこからともなく出てくるようです。誰でもこれで私を助けてもらえますか? 私は解決するのにイライラしていません。

4

1 に答える 1

2

desc は予約済みのキーワードで、句ごとに降順だと思います。

代わりに `des` を実行

于 2013-01-26T06:18:52.783 に答える