internal NoteClass MakeNote(IDataRecord reader) { int id = reader.GetInt32(0); string titel = reader.GetString(1); string note = reader.GetString(2); NoteClass tmpNote = new NoteClass(id, titel, note); return(tmpNote); }
public void UpdateNote(NoteClass noteClass) { const string updateOpskrift = "Update Noter Set Titel=@Titel,Note=@Note where Id=@id"; using (SqlConnection dataConnection = new SqlConnection(ConnectionString)) { dataConnection.Open(); using (SqlCommand updateCommand = new SqlCommand(updateOpskrift, dataConnection)) { updateCommand.Parameters.AddWithValue("@id", noteClass.Id); updateCommand.Parameters.AddWithValue("@Titel", noteClass.Titel); updateCommand.Parameters.AddWithValue("@Note", noteClass.Note); updateCommand.ExecuteNonQuery(); } } }
public int PostNote(NoteClass noteClass) { const string insertNote = "insert into Noter (Titel, Note) values (@Titel, @Note)"; using (SqlConnection dataConnection = new SqlConnection(ConnectionString)) { dataConnection.Open(); using (SqlCommand insertCommand = new SqlCommand(insertNote, dataConnection)) { insertCommand.Parameters.AddWithValue("@Titel", noteClass.Titel); insertCommand.Parameters.AddWithValue("@Note", noteClass.Note); int inters = insertCommand.ExecuteNonQuery(); if (inters != 0) { return(1); } return(0); } } }