private static int DoRegisterNewTodoInDb(ToDoInfo todoDetails) { int returnVal = 0; MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); //define the connection used by the command object msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "INSERT INTO todo(id,date,todo) " + "VALUES(@id,@date,@details)"; msqlCommand.Parameters.AddWithValue("@id", todoDetails.id); msqlCommand.Parameters.AddWithValue("@date", todoDetails.date); msqlCommand.Parameters.AddWithValue("@details", todoDetails.details); msqlCommand.ExecuteNonQuery(); returnVal = 1; } catch (Exception er) { returnVal = 0; } finally { //always close the connection msqlConnection.Close(); } return returnVal; }
public static int DoRegisterNewTodo(ToDoInfo todoDetails) { return DoRegisterNewTodoInDb(todoDetails); }