Esempio n. 1
0
        public bool add(Daomu d)
        {
            bool   result = false;
            string addSQL = "INSERT INTO daomu (";

            foreach (string s in d.getSQLStruct())
            {
                addSQL = addSQL + s + ",";
            }
            addSQL = addSQL.Substring(0, addSQL.Length - 1);
            addSQL = addSQL + ") VALUES (";
            foreach (string s in d.getSQLData())
            {
                addSQL = addSQL + "'" + s + "',";
            }
            addSQL = addSQL.Substring(0, addSQL.Length - 1);
            addSQL = addSQL + ")";
            try
            {
                MySqlCommand    cmd    = new MySqlCommand(addSQL, conn);
                MySqlDataReader myData = cmd.ExecuteReader();
                result = true;
                myData.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show("錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message);
            }
            return(result);
        }
Esempio n. 2
0
        public bool edit(Daomu d, Daomu old)
        {
            bool   result = false;
            string addSQL = "UPDATE daomu SET ";

            for (int i = 0; i < d.getSQLStruct().Count; i++)
            {
                addSQL = addSQL + d.getSQLStruct().ElementAt(i) + " = '" + d.getSQLData().ElementAt(i) + "',";
            }
            addSQL = addSQL.Substring(0, addSQL.Length - 1);
            addSQL = addSQL + " WHERE id = '" + old._Id + "'";
            try
            {
                MySqlCommand    cmd    = new MySqlCommand(addSQL, conn);
                MySqlDataReader myData = cmd.ExecuteReader();
                result = true;
                myData.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(old._Id + "\n錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message);
            }
            return(result);
        }