static internal IList <string> GetDatas(string title) { AllDatas.TitlesAndContent.Clear(); string query = "Select Content, AddDate, UpdateData from datas where Title = " + string.Format($" '{title}'"); AllDatas.TitlesAndContent.Add(title); if (DatabaseConn.conn.State != ConnectionState.Open) { DatabaseConn.Connect(); } MySqlCommand command = new MySqlCommand(query, DatabaseConn.conn); //MessageBox.Show(string.Format(" '{0}'", title)); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { AllDatas.TitlesAndContent.Add(reader.GetString(0)); AllDatas.TitlesAndContent.Add(reader.GetString(1)); AllDatas.TitlesAndContent.Add(reader.GetString(2)); } DatabaseConn.Disconnect(); return(AllDatas.TitlesAndContent); }
static internal IList <string> GetDatas() { AllDatas.TitlesList.Clear(); if (DatabaseConn.conn.State != ConnectionState.Open) { DatabaseConn.Connect(); } MySqlCommand command = new MySqlCommand("Select title from datas", DatabaseConn.conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { AllDatas.TitlesList.Add(reader.GetString(0)); } DatabaseConn.Disconnect(); return(AllDatas.TitlesList); }
static internal string Deleting(string title) { if (DatabaseConn.conn.State != System.Data.ConnectionState.Open) { DatabaseConn.Connect(); } string query = string.Format($"Delete from datas where title = '{title}'"); MySqlCommand command = new MySqlCommand(query, DatabaseConn.conn); if (command.ExecuteNonQuery() > 0) { return("Poprawnie usunięto!"); } DatabaseConn.Disconnect(); return("Błąd usuwania"); }
static internal string Insert(string Title, string Content) { if (DatabaseConn.conn.State != ConnectionState.Open) { DatabaseConn.Connect(); } string query = string.Format("Insert into datas " + "(Title, Content) " + $"values ('{Title}', '{Content}')"); //MessageBox.Show(query); MySqlCommand command = new MySqlCommand(query, DatabaseConn.conn); if (command.ExecuteNonQuery() > 0) { return("Wpisano prawidłowo!"); } return("Błąd wpisywanie"); }
static internal string Update(string title, string content) { if (DatabaseConn.conn.State != System.Data.ConnectionState.Open) { DatabaseConn.Connect(); } string query = string.Format( $"Update datas set Content = '{content}'" + $" where Title = '{title}'"); MySqlCommand command = new MySqlCommand(query, DatabaseConn.conn); //MessageBox.Show(query); if (command.ExecuteNonQuery() > 0) { return("Poprawnie wpisano"); } DatabaseConn.Disconnect(); return("Błąd"); }