示例#1
0
        private void btnAddProduct_Click(object sender, RoutedEventArgs e)
        {
            VendorProductsModel model = new VendorProductsModel()
            {
                VendorId    = Convert.ToInt32(txtVendorId.Text),
                Description = txtDescription.Text,
                Price       = Convert.ToDouble(txtPrice.Text)
            };

            dbConnect.AddVendorProduct(model);

            txtDescription.Text = "";
            txtPrice.Text       = "";
            MessageBox.Show("Vendor Product Added Successfully");
        }
        public void AddVendorProduct(VendorProductsModel vendorProductsModel)
        {
            string    connectionString = CreateDatabase();
            DataTable dt = new DataTable();



            using (SqlCeCommand comm = new SqlCeCommand())
            {
                comm.Connection  = new SqlCeConnection(connectionString);
                comm.CommandType = CommandType.Text;
                comm.CommandText = "insert into VendorProducts (VendorId, Description, Price) values (@VendorId, @Description, @Price)";

                comm.Parameters.AddWithValue("@VendorId", vendorProductsModel.VendorId);
                comm.Parameters.AddWithValue("@Description", vendorProductsModel.Description);
                comm.Parameters.AddWithValue("@Price", vendorProductsModel.Price);

                comm.Connection.Open();
                comm.ExecuteNonQuery();
                comm.Connection.Close();
            }
        }