我收到以下錯誤,無法發現問題:Mysql的語法錯誤
您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法使用近'串」,‘串’,‘6’,‘字符串’,‘串’,‘串’,‘的’在行手冊1
C#代碼:
protected void updateDB(byte[] content, int size, string mime)
{
string school = DropDownList_School.Text;
string subject = DropDownList_Subject.Text;
string teacher = DropDownList_Teacher.Text;
string course = DropDownList_Class.Text;
string unit = TextBox_Unit.Text;
string name = TextBox_Name.Text;
string date = DateTime.Today.ToString();
string username = System.Web.Security.Membership.GetUser().UserName;
MySqlConnection connection = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString);
connection.Open();
MySqlCommand cmd = new MySqlCommand();//(query, connection);
cmd.Connection = connection;
cmd.CommandText = "INSERT INTO uploads
(@School, @Subject, @Teacher, @Course, @Unit, @Name, @Username, @Size, @MIME, @content) ";
cmd.Prepare();
cmd.Parameters.AddWithValue("@School", school);
cmd.Parameters.AddWithValue("@Subject", subject);
cmd.Parameters.AddWithValue("@Teacher", teacher);
cmd.Parameters.AddWithValue("@Course", course);
cmd.Parameters.AddWithValue("@Unit", unit);
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Username", username);
cmd.Parameters.AddWithValue("@Size", size);
cmd.Parameters.AddWithValue("@MIME", mime);
cmd.Parameters.AddWithValue("@content", content);
cmd.ExecuteNonQuery();
connection.Close();
}
ConnectionString中是正確的。
嘗試INSERT INTO上傳(FIELD1,FIELD2)VALUES(@值1,@值2) – B4NZ41
@Fernando科斯塔:字段和價值觀是沒有必要的,如果將值插入表中的所有領域 - 的有機磷農藥查詢有效 –
@OMG小馬,很好的做法,使用它們,因爲如果他們是同一類型的那麼SQL能猜出這列不當(特別是如果你把他們在錯誤的順序意外和類型都有效) –