public static Revenue SelectallObjectwithID(int _id) { Revenue fo = null; string connectionString = ConfigurationManager.ConnectionStrings["cStr"].ConnectionString; using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); string query = "SELECT * FROM revenue WHERE id = " + _id; SqlCommand cmd = new SqlCommand(query, cn); using (SqlDataReader dataReader = cmd.ExecuteReader()) { while (dataReader.Read()) { fo = new Revenue(); fo.id = Convert.ToInt32(dataReader["id"]); fo.name = dataReader["name"].ToString(); fo.year = dataReader["year"].ToString(); fo.month = dataReader["month"].ToString(); fo.money = Convert.ToDouble(dataReader["money"].ToString()); return(fo); } } cn.Close(); } return(fo); }
public static List <Revenue> SelectallObject() { List <Revenue> list = new List <Revenue>(); string connectionString = ConfigurationManager.ConnectionStrings["cStr"].ConnectionString; using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); string query = "SELECT * FROM revenue"; SqlCommand cmd = new SqlCommand(query, cn); using (SqlDataReader dataReader = cmd.ExecuteReader()) { while (dataReader.Read()) { Revenue fo = new Revenue(); fo.id = Convert.ToInt32(dataReader["id"]); fo.name = dataReader["name"].ToString(); fo.year = dataReader["year"].ToString(); fo.month = dataReader["month"].ToString(); fo.money = Convert.ToDouble(dataReader["money"].ToString()); list.Add(fo); } } cn.Close(); } return(list); }