Aizaz Ahsan

Aizaz Ahsan

  • NA
  • 3
  • 413

Selecting list view item to edit the info inside a SQL database

Jun 10 2021 8:34 PM

Hi, first time here on this platform. Anyway, I am working on a c# project at school, where you create a database in SQL and work on that database to create an application for a restaurant. All the code is kept in separate layers. I created a windows form in the UI layer and I want to select a row. After selecting a row, I wanna edit the information in the row but not all columns at once. 

How can I make it possible to select a row item and then edit it?  Thanks in advance.

 

DAL Layer: 

public List<Item> Get_All_Items_DB()
        {
            String query = "select itemID, [name], price, stock, category, Course, VATRate from ITEMS";
            SqlParameter[] parameters = new SqlParameter[0];

            return ReadItems(ExecuteSelectQuery(query, parameters));
        }

DAO Layer:

ItemDAL itemDAO = new ItemDAL();
        
        public List<Item> GetItems()
        {
            return itemDAO.Get_All_Items_DB();
        }

UI code: 

 private void GetItemList()
        {
            itemService = new Item_Service();
            List<Item> menuItems = itemService.GetItems();
            listViewDisplayForm.Items.Clear();

            foreach (Item i in menuItems)
            {
                lvItem = new ListViewItem(i.ItemID.ToString(), 0);
                lvItem.SubItems.Add(i.Name);
                lvItem.SubItems.Add(i.Price.ToString("0.00"));
                lvItem.SubItems.Add(i.Stock.ToString("0"));
                lvItem.SubItems.Add(i.Category.ToString());
                lvItem.SubItems.Add(i.Course.ToString());
                lvItem.SubItems.Add(i.VATRate.ToString("0.00"));

                listViewDisplayForm.Items.Add(lvItem);
            }
        }

private void butDisplay_Click(object sender, EventArgs e)
        {
            GetItemList();
        }


Attachment: Screenshot_(98).zip

Answers (1)