public bool add(Making m) { bool result = false; string addSQL = "INSERT INTO making ("; foreach (string s in m.getSQLStruct()) { addSQL = addSQL + s + ","; } addSQL = addSQL.Substring(0, addSQL.Length - 1); addSQL = addSQL + ") VALUES ("; foreach (string s in m.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); }
public bool edit(Making m, Making old) { bool result = false; string addSQL = "UPDATE making SET "; for (int i = 0; i < m.getSQLStruct().Count; i++) { addSQL = addSQL + m.getSQLStruct().ElementAt(i) + " = '" + m.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("錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message); } return(result); }