public static int Insert(Playlist playlist) { try { using (MySqlConnection conn = new MySqlConnection(App.setting.connectString)) { conn.Open(); string query = "p_insert_playlist"; using (MySqlCommand cmd = new MySqlCommand(query, conn)) { cmd.Parameters.Add(new MySqlParameter("@_playlist_name", MySqlDbType.VarChar,100) { Direction = System.Data.ParameterDirection.Input, Value = playlist.Name }); cmd.Parameters.Add(new MySqlParameter("@_playlist_user", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = playlist.user_id }); cmd.Parameters.Add(new MySqlParameter("@_playlist_comment", MySqlDbType.VarChar, 100) { Direction = System.Data.ParameterDirection.Input, Value = playlist.Comment }); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.ExecuteScalar(); }; conn.Close(); }; return 1; } catch (MySqlException) { return -1; } catch (Exception) { return -2; } }
public static Playlist toPlaylist(this MySqlDataReader reader) { if (reader.HasRows) { Playlist d = null; while (reader.Read()) { if (!reader.IsDBNull(0)) { d = new Playlist(); d.ID = reader.GetInt32(Define.playlist_id); d.Name = reader.GetString(Define.playlist_name); d.Time = reader.GetDateTime(Define.playlist_datetime); d.user_id = reader.GetInt32(Define.playlist_user); d.Status = reader.GetBoolean(Define.playlist_status); d.Default = reader.GetBoolean(Define.playlist_default); try { d.Comment = reader.GetString(Define.playlist_comment); } catch (Exception) { } } } return d; } return null; }