簡體   English   中英

C#網站-表示數據庫中對象的類給我VS2015中的錯誤CS0246

[英]C# Website - Class representing an object in a database is giving me the error CS0246 in VS2015

我正在進行的練習提供了解決方案和一個幾乎完整的項目。 當我創建一個類級別的變量時,將出現一個問題,該變量將保存從數據庫文件Halloween.mdf填充的下拉列表中選擇的Product對象。

代碼:Order.aspx.cs(文件給我錯誤)

using System;
using System.Web.UI;
using System.Data;

public partial class Order : System.Web.UI.Page
{
    private Product selectedProduct;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) ddlProducts.DataBind();
        selectedProduct = this.GetSelectedProduct();
        lblName.Text = selectedProduct.Name;
        lblShortDescription.Text = selectedProduct.ShortDescription;
        lblLongDescription.Text = selectedProduct.LongDescription;
        lblUnitPrice.Text = selectedProduct.UnitPrice.ToString("c") + " each";
        imgProduct.ImageUrl = "Images/Products/" + selectedProduct.ImageFile;
    }
    private Product GetSelectedProduct()
    {
        DataView productsTable = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        productsTable.RowFilter = string.Format("ProductID = '{0}'", ddlProducts.SelectedValue);
        DataRowView row = (DataRowView)productsTable[0];

        Product p = new Product();
        p.ProductID = row["ProductID"].ToString();
        p.Name = row["Name"].ToString();
        p.ShortDescription = row["ShortDescription"].ToString();
        p.LongDescription = row["LongDescription"].ToString();
        p.UnitPrice = (decimal)row["UnitPrice"];
        p.ImageFile = row["ImageFile"].ToString();
        return p;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CartItemList cart = CartItemList.GetCart();
            CartItem cartItem = cart[selectedProduct.ProductID];
            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
            }
            Response.Redirect("Cart.aspx");
        }
    }
}

我收到錯誤消息“找不到類型或名稱空間名稱'Product'(是否缺少using指令或程序集引用?)。

當我查看解決方案項目時,我可以看到在Assembly App代碼中定義了類級變量Product。

我不確定這是什么問題,由於我的困惑,我很難尋求幫助。

任何幫助表示贊賞。

這個問題微不足道。 該目錄錯誤,不得不將項目移出它所在的文件夾,這解決了所有問題。 謝謝大家的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM