Ejemplo n.º 1
0
        public void addProduct(ProductModels product)
        {
            string cs = ConfigurationManager.ConnectionStrings["Con"].ConnectionString;

            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("addProduct", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramPrice = new SqlParameter();
                paramPrice.ParameterName = "@Price";
                paramPrice.Value         = product.Price;
                cmd.Parameters.Add(paramPrice);

                SqlParameter paramColor = new SqlParameter();
                paramColor.ParameterName = "@Color";
                paramColor.Value         = product.Color;
                cmd.Parameters.Add(paramColor);

                SqlParameter paramStorage = new SqlParameter();
                paramStorage.ParameterName = "@Storage";
                paramStorage.Value         = product.Storage;
                cmd.Parameters.Add(paramStorage);

                SqlParameter paramProcessor = new SqlParameter();
                paramProcessor.ParameterName = "@Processor";
                paramProcessor.Value         = product.Processor;
                cmd.Parameters.Add(paramProcessor);

                SqlParameter paramMemory = new SqlParameter();
                paramMemory.ParameterName = "@Memory";
                paramMemory.Value         = product.Memory;
                cmd.Parameters.Add(paramMemory);

                SqlParameter paramDisplay = new SqlParameter();
                paramDisplay.ParameterName = "@Display";
                paramDisplay.Value         = product.Display;
                cmd.Parameters.Add(paramDisplay);

                SqlParameter paramDetails = new SqlParameter();
                paramDetails.ParameterName = "@Details";
                paramDetails.Value         = product.Details;
                cmd.Parameters.Add(paramDetails);

                SqlParameter paramBrandId = new SqlParameter();
                paramBrandId.ParameterName = "@BrandId";
                paramBrandId.Value         = product.BrandId;
                cmd.Parameters.Add(paramBrandId);

                SqlParameter paramModelId = new SqlParameter();
                paramModelId.ParameterName = "@ModelId";
                paramModelId.Value         = product.ModelId;
                cmd.Parameters.Add(paramModelId);

                SqlParameter paramCategoryId = new SqlParameter();
                paramCategoryId.ParameterName = "@CategoryId";
                paramCategoryId.Value         = product.CategoryId;
                cmd.Parameters.Add(paramCategoryId);

                SqlParameter paramCreatedBy = new SqlParameter();
                paramCreatedBy.ParameterName = "@CreatedBy";
                paramCreatedBy.Value         = product.CreatedBy;
                cmd.Parameters.Add(paramCreatedBy);

                SqlParameter paramCreatedDate = new SqlParameter();
                paramCreatedDate.ParameterName = "@CreatedDate";
                paramCreatedDate.Value         = product.CreatedDate;
                cmd.Parameters.Add(paramCreatedDate);

                con.Open();
                int Id = Convert.ToInt32(cmd.ExecuteScalar());
                product.Id = Id;
            }
        }