Mysql语法错误
本文关键字:错误 语法 Mysql | 更新日期: 2023-09-27 18:01:57
我收到以下错误,找不到问题:
c#代码:你的SQL语法有错误;检查与你的MySQL服务器版本对应的手册,以便在第1行"字符串","字符串","6","字符串","字符串","字符串","the"附近使用正确的语法
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 uploads VALUES(...)
您可能还想指定列顺序,如INSERT INTO uploads(col1, col2, etc...) VALUES(val for col1, val for col2..., etc)
,因为如果没有,那么SQL将尝试"猜测",它可能会猜错。