I am new to programming, so please be kind. I am working on a final project for C# specifically within ASP.NET. For this project it has been a three part cumulative of CRUD. We are working with a MySQL database of teachers, courses and students.
This is the error I received:
Error I am receiving in Visual Studio: SQL Exception
I have created a controller to handle the update functionality of CRUD. I have tried with creating my SQL query and while attempting to test it within swagger, I ran into an exception. This is what I currently have:
/// <summary>
/// controller that
/// Updates a teachers information
/// </summary>
/// <example>
/// POST:
/// </example>
/// <returns></returns>
[HttpPost(template: "UpdateTeacher")]
public int UpdateTeacher([FromForm] string teacherfname, [FromForm] string teacherlname, [FromForm] string employeenumber, [FromForm] DateTime hiredate, [FromForm] float salary)
{
using (MySqlConnection Connection = _context.AccessDatabase())
{
Connection.Open();
MySqlCommand Command = Connection.CreateCommand();
string SqlFormattedDate = hiredate.ToString("yyyy-MM-dd HH:mm:ss");
Command.CommandText = $"UPDATE INTO teachers (teacherfname, teacherlname,employeenumber, hiredate, salary) VALUES ('{teacherfname}','{teacherlname}', {employeenumber}','{SqlFormattedDate}',{salary}')";
return Command.ExecuteNonQuery();
}
}