public List <Specials> GetSpecials() { List <Specials> specials = new List <Specials>(); using (var cn = new SqlConnection("Server=localhost;Database=GuildCars;User Id=sa;Password=sqlserver;")) { SqlCommand cmd = new SqlCommand("DisplaySpecials", cn); cmd.CommandType = CommandType.StoredProcedure; cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { Specials currentRow = new Specials(); currentRow.SpecialId = (int)dr["SpecialId"]; currentRow.SpecialTitle = dr["SpecialTitle"].ToString(); currentRow.SpecialDescription = dr["SpecialDescription"].ToString(); specials.Add(currentRow); } } } return(specials); }
public Specials GetSpecialById(int specialId) { Specials special = new Specials(); special.SpecialId = specialId; using (var cn = new SqlConnection("Server=localhost;Database=GuildCars;User Id=sa;Password=sqlserver;")) { SqlCommand cmd = new SqlCommand("GetSpecialById", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SpecialId", specialId); cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { special.SpecialTitle = dr["SpecialTitle"].ToString(); special.SpecialDescription = dr["SpecialDescription"].ToString(); } } } return(special); }
public void UpdateSpecial(Specials special) { using (var cn = new SqlConnection("Server=localhost;Database=GuildCars;User Id=sa;Password=sqlserver;")) { SqlCommand cmd = new SqlCommand("UpdateSpecial", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SpecialTitle", special.SpecialTitle); cmd.Parameters.AddWithValue("@SpecialDescription", special.SpecialDescription); cmd.Parameters.AddWithValue("@SpecialId", special.SpecialId); cn.Open(); cmd.ExecuteNonQuery(); } }
public void InsertSpecial(Specials special) { using (var cn = new SqlConnection("Server=localhost;Database=GuildCars;User Id=sa;Password=sqlserver;")) { SqlCommand cmd = new SqlCommand("InsertSpecial", cn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@SpecialId", SqlDbType.Int); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param); cmd.Parameters.AddWithValue("@SpecialTitle", special.SpecialTitle); cmd.Parameters.AddWithValue("@SpecialDescription", special.SpecialDescription); cn.Open(); cmd.ExecuteNonQuery(); special.SpecialId = (int)param.Value; }; }