public string UpDateHeader(HeaderEntityDL headerToDB) { try { using (EntityFramework accessToDB = new EntityFramework()) { accessToDB.Entry(headerToDB).State = EntityState.Modified; accessToDB.SaveChanges(); return("Die Anforderung wurde erfüllt"); } } catch (Exception ex) { string error = $"Die Anforderung wurde nicht erfüllt. Unten Fehlerbeschreibung: \n{ex.Message.ToString()}"; return(error); } //using (SqlConnection connection = new SqlConnection(ConnectionString)) //{ // connection.Open(); // using (SqlCommand command = new SqlCommand("UPDATE Header SET Title=@Title, Text=@Text , Link1Text=@Link1Text, Link1Address=@Link1Address, Link2Text=@Link2Text, Link2Address=@Link2Address", connection)) // { // command.Parameters.AddWithValue("@Title", headerToDB.Title); // command.Parameters.AddWithValue("@Text", headerToDB.Text); // command.Parameters.AddWithValue("@Link1Text", headerToDB.Link1.LinkText); // command.Parameters.AddWithValue("@Link1Address", headerToDB.Link1.LinkAddress); // command.Parameters.AddWithValue("@Link2Text", headerToDB.Link2.LinkText); // command.Parameters.AddWithValue("@Link2Address", headerToDB.Link2.LinkAddress); // command.ExecuteNonQuery(); // } //} }
//private const string ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=WebDB;Integrated Security=True"; // HEADER public HeaderEntityDL GetHeaderData() { try { using (EntityFramework accessToDB = new EntityFramework()) { return(accessToDB.HeaderEntityDLTable.SingleOrDefault()); } } catch (Exception ex) { HeaderEntityDL error = new HeaderEntityDL(); error.Title = "Die KopfSeite wurde nicht eingelesen"; error.Text = "Unten Fehlerbeschreibung: \n"; error.Link1.LinkText = ex.Message.ToString(); return(error); } //using (SqlConnection connection = new SqlConnection(ConnectionString)) //{ // connection.Open(); // using (SqlCommand command = new SqlCommand("SELECT Title,Text,Link1Text,Link1Address,Link2Text,Link2Address FROM Header", connection)) // { // using (SqlDataReader reader = command.ExecuteReader()) // { // if (!reader.Read()) // { // return null; // } // HeaderEntityDL headerEntityDL = new HeaderEntityDL(); headerEntityDL.Link1 = new LinkDL(); headerEntityDL.Link2 = new LinkDL(); // headerEntityDL.Title = reader.GetString(reader.GetOrdinal("Title")); // headerEntityDL.Text = reader.GetString(reader.GetOrdinal("Text")) ?? string.Empty; // headerEntityDL.Link1.LinkText = reader.GetString(reader.GetOrdinal("Link1Text")) ?? string.Empty; // headerEntityDL.Link1.LinkAddress = reader.GetString(reader.GetOrdinal("Link1Address")) ?? string.Empty; // headerEntityDL.Link2.LinkText = reader.GetString(reader.GetOrdinal("Link2Text")) ?? string.Empty; // headerEntityDL.Link2.LinkAddress = reader.GetString(reader.GetOrdinal("Link2Address")) ?? string.Empty; // return headerEntityDL; // } // } //} }