Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Item> AllItems()
- {
- SqlConnection connection=new SqlConnection(connectionString);
- try
- {
- List<Item> itemList=new List<Item>();
- string selectQuery = "SELECT * FROM ItemTable";
- SqlCommand command=new SqlCommand(selectQuery,connection);
- connection.Open();
- SqlDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- Item item=new Item();
- item.Name = reader["Name"].ToString();
- item.Price = Convert.ToDecimal(reader["Price"]);
- itemList.Add(item);
- }
- reader.Close();
- connection.Close();
- return itemList;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement