'附近使用正確的語法我試圖用我的Asp.NET項目將html頁面插入到MySQL中,但出現錯誤;你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'
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 'de Osman patlaması', '', '<div style=\"text-align: center\">\r\n<img src=\"/i' at line 1
我該如何解決這個問題我的服務器端代碼是;
MySqlConnection myCon = new MySqlConnection();
myCon.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
MySqlCommand cmd = new MySqlCommand();
cmd.CommandType = CommandType.Text;
string query = @"INSERT INTO `test`.`posts` (`id`, `author`, `title`, `description`, `content`, `ispublished`, `iscommentsenabled`, `pubDate`, `lastModified`, `raters`, `rating`, `slug`, `tags`, `categories`) VALUES (NULL, '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')";
query = String.Format(query, p.author, p.title, p.description, p.content, p.ispublished, p.iscommentsenabled, p.pubDate, p.lastModified, p.raters, p.rating, p.slug, p.tags, p.categories);
cmd.CommandText = query;
cmd.Connection = myCon;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
感謝您的幫助。
MySqlConnection myCon = new MySqlConnection();
myCon.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
MySqlCommand cmd = new MySqlCommand(@"INSERT INTO posts (id, author , title , description , content , ispublished , iscommentsenabled , pubDate
, lastModified , raters , rating , slug , tags , categories)
VALUES (@id ,@author ,@title ,@description ,@content ,@ispublished ,@iscommentsenabled ,@pubDate ,@lastModified ,@raters ,@rating ,@slug ,@tags ,
@categories))", myCon);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@id", null);
cmd.Parameters.AddWithValue("@author", p.author);
cmd.Parameters.AddWithValue("@title", p.title);
cmd.Parameters.AddWithValue("@description", p.description);
cmd.Parameters.AddWithValue("@content", p.content);
cmd.Parameters.AddWithValue("@ispublished", p.ispublished);
cmd.Parameters.AddWithValue("@iscommentsenabled", p.iscommentsenabled);
cmd.Parameters.AddWithValue("@pubDate", p.pubDate);
cmd.Parameters.AddWithValue("@lastModified", p.lastModified);
cmd.Parameters.AddWithValue("@raters", p.raters);
cmd.Parameters.AddWithValue("@rating", p.rating);
cmd.Parameters.AddWithValue("@slug", p.slug);
cmd.Parameters.AddWithValue("@tags", p.tags);
cmd.Parameters.AddWithValue("@categories", p.categories);
myCon.Open();
cmd.Prepare();
cmd.ExecuteNonQuery();
myCon.Close();
請用實際數據顯示最終查詢 – 2010-10-07 13:21:17