Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.OleDb;
- using System.Data.SqlClient;
- using System.Web.Configuration;
- using System.Data;
- namespace WebApplication3.classi
- {
- public class NewsService
- {
- public News CaricaNotizia(int id)
- {
- database db = new database();
- News notizia = null;
- string querypagina = "SELECT * FROM NEWS";
- OleDbDataReader reader = db.EseguiReader(querypagina);
- if (reader.Read())
- {
- notizia = new News();
- notizia.id = Int32.Parse(reader["id"].ToString());
- notizia.titolo = reader["titolo"].ToString();
- notizia.contenuto = reader["contenuto"].ToString();
- }
- return notizia;
- }
- public bool delNotizia(int _id)
- {
- database db = new database();
- string query = "delete from notizie where id=" + _id;
- return db.AggiornaDB(query);
- }
- public List<News> mlistanews()
- {
- database db = new database();
- List<News> notizia = new List<News>();
- News n;
- string querypagina = "SELECT * FROM NOTIZIE";
- OleDbDataReader reader = db.EseguiReader(querypagina);
- while (reader.Read())
- {
- n = new News();
- n.id = Int32.Parse(reader["id"].ToString());
- n.titolo = reader["titolo"].ToString();
- notizia.Add(n);
- }
- return notizia;
- }
- public int insertNotizia(News n)
- {
- Data.DB.OleDbDatabase db = new Data.DB.OleDbDatabase();
- OleDbCommand cmd = new OleDbCommand();
- cmd.CommandText = "INSERT INTO NOTIZIE (titolo,contenuto,data) VALUES (?,?,?)";
- cmd.Parameters.AddWithValue("titolo", n.titolo);
- cmd.Parameters.AddWithValue("contenuto", n.contenuto);
- cmd.Parameters.AddWithValue("data", n.data);
- return db.EseguiNonQuery(cmd);
- }
- public int aggNotizia(News n)
- {
- Data.DB.OleDbDatabase db = new Data.DB.OleDbDatabase();
- OleDbCommand cmd = new OleDbCommand();
- cmd.CommandText = "UPDATE NOTIZIe SET titolo=?, contenuto=? data=? WHERE id=?";
- cmd.Parameters.AddWithValue("titolo", n.titolo);
- cmd.Parameters.AddWithValue("contenuto", n.contenuto);
- cmd.Parameters.AddWithValue("data", n.data);
- cmd.Parameters.AddWithValue("id", n.id);
- int cotto;
- cotto = db.EseguiNonQuery(cmd);
- if (cotto == 1) return (1); else return (0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement