public void InsertAuthor(Author author) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(INSERT_AUTHOR, conn); /* Add parameters into the command */ command.Parameters.AddWithValue("@author_name", author.author_name); command.Parameters.AddWithValue("@author_surname", author.author_surname); command.Parameters.AddWithValue("@author_middle_name", author.author_middle_name); command.Parameters.AddWithValue("@author_birth_date", author.author_birth_date); /* Executes the command ppp*/ command.ExecuteNonQuery(); } }
protected void Button7_Click(object sender, EventArgs e) { //prida do author DatabaseLibrary.Author aut = new DatabaseLibrary.Author(); aut.author_name = TextBox_author_name.Text; aut.author_surname = TextBox_author_surname.Text; aut.author_middle_name = TextBox_author_middle_name.Text; string author_birthDate = TextBox_author_birth_date.Text; string[] items = author_birthDate.Split('/'); DateTime birthDate_author = new DateTime(Int32.Parse(items[2]), Int32.Parse(items[1]), Int32.Parse(items[0])); aut.author_birth_date = birthDate_author; new DatabaseLibrary.AuthorTable().InsertAuthor(aut); Response.Redirect(Request.RawUrl); }
public List<Author> SelectAll() { List<Author> autList = new List<Author>(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ALL, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Author author = new Author(); author.author_id = reader.GetInt32(0); author.author_name = reader.GetString(1); author.author_surname = reader.GetString(2); author.author_middle_name = !reader.IsDBNull(3) ? reader.GetString(3) : null; author.author_birth_date = reader.GetDateTime(4); autList.Add(author); } } return autList; }
public void Update(Author author) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(UPDATE_AUTHOR, conn); command.Parameters.AddWithValue("@author_id", author.author_id); command.Parameters.AddWithValue("@author_name", author.author_name); command.Parameters.AddWithValue("@author_surname", author.author_surname); command.Parameters.AddWithValue("@author_middle_name", author.author_middle_name); command.Parameters.AddWithValue("@author_birth_date", author.author_birth_date); /* Executes the command */ command.ExecuteNonQuery(); } }
public Author SelectOne(int authorId) { Author author = new Author(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ONE, conn); command.Parameters.AddWithValue("@author_id", authorId); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { author.author_id = reader.GetInt32(0); author.author_name = reader.GetString(1); author.author_surname = reader.GetString(2); author.author_middle_name = reader.GetString(3); author.author_birth_date = reader.GetDateTime(4); } reader.Close(); } return author; }