Exemplo n.º 1
0
        public void Insert(StockItem stockItem)
        {
            try
            {
                string q = "INSERT INTO STOCKITEM VALUES (@id, @name, @desc, @sNo, @qty, @price, @category);";

                var cmd = new SqlCommand(q, conn);

                cmd.Parameters.AddWithValue("@id", stockItem.Id);
                cmd.Parameters.AddWithValue("@name", stockItem.Name);
                cmd.Parameters.AddWithValue("@desc", stockItem.Desc);
                cmd.Parameters.AddWithValue("@sNo", stockItem.Sno);
                cmd.Parameters.AddWithValue("@qty", stockItem.Qty);
                cmd.Parameters.AddWithValue("@price", stockItem.Price);
                cmd.Parameters.AddWithValue("@category", stockItem.Category);

                cmd.ExecuteNonQuery();
            }

            catch
            {
                MessageBox.Show("Duplicate Primary Key. Please enter a different Id Number");
            }
        }