コード例 #1
0
        public static void ConnectInsertToDoListTable(ToDoData tdData)
        {
            //define the connection reference and initialize it
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "INSERT INTO to_do(date_time,to_do,id)" + "VALUES(@date_time,@to_do,@id)";

                msqlCommand.Parameters.AddWithValue("@date_time", tdData.date_time);
                msqlCommand.Parameters.AddWithValue("@to_do", tdData.to_do);
                msqlCommand.Parameters.AddWithValue("@id", tdData.id);

                msqlCommand.ExecuteNonQuery();

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
        }
コード例 #2
0
        private ToDoData AddNewToDo()
        {
            ToDoData tdData;
            tdData = new ToDoData();
            tdData.date_time = DateTime.Now;
            tdData.to_do = todoInputTb.Text;
            tdData.id = "T-" + DateTime.Now.ToOADate().ToString();

            return tdData;
        }
コード例 #3
0
        public static List<ToDoData> fetcheToDoData()
        {
            List<ToDoData> _toDoCollection = new List<ToDoData>();

            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();
            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlCommand.CommandText = "Select * from to_do;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    ToDoData ToDoData = new ToDoData();
                    ToDoData.to_do = msqlReader.GetString("to_do");
                    ToDoData.date_time = msqlReader.GetDateTime("date_time");
                    ToDoData.id = msqlReader.GetString("id");

                    _toDoCollection.Add(ToDoData);

                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return _toDoCollection;
        }