Reputation: 2301
I am receiving the following error and cannot find the problem:
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 ''String', 'String', '6', 'String', 'String', 'String', 'The' at line 1
C# code:
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();
}
The ConnectionString is correct.
Upvotes: 1
Views: 309
Reputation: 23268
should be INSERT INTO uploads VALUES(...)
You might also want to specify the column order such as INSERT INTO uploads(col1, col2, etc...) VALUES(val for col1, val for col2..., etc)
because if not then SQL will try to "guess" and it can guess wrong.
Upvotes: 1