public static Author GetAuthor(string id) { Author author = new Author(); using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = conn.CreateCommand()) { comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "GetAuthor"; comm.Parameters.AddWithValue("@id", id); conn.Open(); var reader = comm.ExecuteReader(); if (reader.Read()) { author.AuthorID = reader["au_id"] as string; author.FirstName = reader["au_fname"] as string; author.LastName = reader["au_lname"] as string; author.Phone = reader["phone"] as string; author.Address = reader["address"] as string; author.City = reader["city"] as string; author.State = reader["State"] as string; author.Zip = reader["zip"] as string; author.Contract = reader["contract"] == null ? false : (bool)reader["contract"]; } conn.Close(); } } return author; }
Author parseForm() { Author author = new Author() { AuthorID = tbxID.Text, FirstName = tbxFirstName.Text, LastName = tbxLastName.Text, Phone = tbxPhone.Text, Address = tbxAddress.Text, City = tbxCity.Text, State = tbxState.Text, Zip = tbxZip.Text, Contract = cbxContract.Checked }; return author; }
void displayAuthor(Author author) { tbxID.Text = author.AuthorID; tbxFirstName.Text = author.FirstName; tbxLastName.Text = author.LastName; tbxPhone.Text = author.Phone; tbxAddress.Text = author.Address; tbxCity.Text = author.City; tbxState.Text = author.State; tbxZip.Text = author.Zip; cbxContract.Checked = (author.Contract == true ? true : false); }
public static int UpdateAuthor(Author author) { int result = 0; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = conn.CreateCommand()) { comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "UpdateAuthor"; comm.Parameters.AddWithValue("@id", author.AuthorID); comm.Parameters.AddWithValue("@fname", author.FirstName); comm.Parameters.AddWithValue("@lname", author.LastName); comm.Parameters.AddWithValue("@phone", author.Phone); comm.Parameters.AddWithValue("@address", author.Address); comm.Parameters.AddWithValue("@city", author.City); comm.Parameters.AddWithValue("@state", author.State); comm.Parameters.AddWithValue("@zip", author.Zip); comm.Parameters.AddWithValue("@contract", author.Contract); conn.Open(); result = comm.ExecuteNonQuery(); conn.Close(); } } return result; }
public static string InsertAuthor(Author author) { string id = ""; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = conn.CreateCommand()) { comm.CommandType = System.Data.CommandType.StoredProcedure; comm.CommandText = "AddAuthor"; comm.Parameters.AddWithValue("@id", author.AuthorID); comm.Parameters.AddWithValue("@fname", author.FirstName); comm.Parameters.AddWithValue("@lname", author.LastName); comm.Parameters.AddWithValue("@phone", author.Phone); comm.Parameters.AddWithValue("@address", author.Address); comm.Parameters.AddWithValue("@city", author.City); comm.Parameters.AddWithValue("@state", author.State); comm.Parameters.AddWithValue("@zip", author.Zip); comm.Parameters.AddWithValue("@contract", author.Contract); SqlParameter p = new SqlParameter("@returnID", SqlDbType.VarChar, 11); p.Direction = ParameterDirection.Output; comm.Parameters.Add(p); conn.Open(); comm.ExecuteNonQuery(); conn.Close(); id = p.Value as string; } } return id; }