C# 找不到命名空间,但已创建?

C# 找不到命名空间,但已创建?,c#,namespaces,syntax-error,C#,Namespaces,Syntax Error,我在做一个差不多完成的项目。但唯一的问题是我无法通过这个错误 错误1:找不到类型或命名空间名称“Item”(是否缺少using指令或程序集引用?) 有人能给我解释一下为什么我收到这个错误,而这个名字确实有一个参考?(据我所知) 这是我为班级准备的。cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using S

我在做一个差不多完成的项目。但唯一的问题是我无法通过这个错误

错误1:找不到类型或命名空间名称“Item”(是否缺少using指令或程序集引用?)

有人能给我解释一下为什么我收到这个错误,而这个名字确实有一个参考?(据我所知)

这是我为班级准备的。cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.IO;
using System.Configuration;
using System.Xml;



namespace ProjectLab4
{
    class LClass5
    {

        public int Item_ID { get; set; }
        public int Invent_id { get; set; }
        public string Itemsize { get; set; }
        public string Color { get; set; }
        public decimal Curr_price { get; set; }
        public int Qoh { get; set; }


        public bool ParseCSVline(string aLine)
        {
            try
            {
                string[] fields = aLine.Split(',');
                this.Item_ID = int.Parse(fields[0]);
                this.Invent_id = int.Parse(fields[1]);
                this.Itemsize = fields[2];
                this.Color = fields[3];
                this.Curr_price = decimal.Parse(fields[4]);
                this.Qoh = int.Parse(fields[5]);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        public bool IsInDatabase(OdbcConnection db)
        {
            String sql = "SELECT * FROM item WHERE item_ID=?";
            OdbcCommand Command = new OdbcCommand(sql, db);

            Command.Parameters.Add("@ID", OdbcType.Int).Value = this.Item_ID;


            if (Command.ExecuteReader().HasRows)
                return true;
            else
                return false;
        }


        public bool AddRow(OdbcConnection db)
        {
            String sql = "INSERT INTO item "
                       + "(item_id, invent_id, itemsize, color, curr_price, qoh) "
                       + "VALUES( ?, ?, ?, ?, ?, ?)";
            OdbcCommand Command = new OdbcCommand(sql, db);
            Command.Parameters.Add("@ID", OdbcType.Int).Value = this.Item_ID;
            Command.Parameters.Add("@INVID", OdbcType.Int).Value = this.Invent_id;
            Command.Parameters.Add("@SZ", OdbcType.VarChar).Value = this.Itemsize.Trim();
            Command.Parameters.Add("@COL", OdbcType.VarChar).Value = this.Color.Trim();
            Command.Parameters.Add("@PR", OdbcType.Double).Value = (double)this.Curr_price;
            Command.Parameters.Add("@QOH", OdbcType.Int).Value = this.Qoh;

            int result = Command.ExecuteNonQuery();  //Returns 1 if successful
            if (result > 0)
                return true;  //Was successful in adding
            else
                return false;  //failed to add
        }

        public bool UpdateRow(OdbcConnection db)
        {
            String sql = "UPDATE item "
                + "SET itemsize=?, "
                + "color=?, "
                + "curr_price=?, "
                + "qoh=? "
                + "WHERE item_id=?";
            OdbcCommand Command = new OdbcCommand(sql, db);
            Command.Parameters.Add("@SZ", OdbcType.VarChar).Value = this.Itemsize.Trim();
            Command.Parameters.Add("@COL", OdbcType.VarChar).Value = this.Color.Trim();
            Command.Parameters.Add("@PR", OdbcType.Double).Value = (double)this.Curr_price;
            Command.Parameters.Add("@QOH", OdbcType.Int).Value = this.Qoh;
            Command.Parameters.Add("@ID", OdbcType.Int).Value = this.Item_ID;
            int result = Command.ExecuteNonQuery(); //Returns 1 if successful
            if (result > 0)
                return true; //Was successful in updating
            else
                return false; //failed to update
        }

        public bool DeleteRow(OdbcConnection db)
        {
            String sql = "DELETE FROM item WHERE item_id=?";
            OdbcCommand Command = new OdbcCommand(sql, db);
            Command.Parameters.Add("@ID", OdbcType.Int).Value = this.Item_ID;
            int result = Command.ExecuteNonQuery(); //Returns 1 if successful
            if (result > 0)
                return true; //Was successful in deleting
            else
                return false; //failed to delete
        }

        public bool parseXML(XmlReader f)
        {
            try
            {
                this.Item_ID = int.Parse(f.GetAttribute("item_id"));
                this.Invent_id = int.Parse(f.GetAttribute("invent_id"));
                this.Itemsize = f.GetAttribute("itemsize");
                this.Color = f.GetAttribute("color");
                this.Curr_price = decimal.Parse(f.GetAttribute("curr_price"));
                this.Qoh = int.Parse(f.GetAttribute("qoh"));
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        //Get this item from the XML file and
        //add this item to the database passed in as db
        public bool XMLAdd(XmlReader f, OdbcConnection db)
        {
            if (!this.parseXML(f))  //parse the item from "f"
                return false;  //Leave if the parse failed


            //Is it in database?  Check that it is NOT.
            if (!this.IsInDatabase(db))
            {
                //if not, add it
                if (this.AddRow(db))
                    return true;
                else
                    return false; //if something went wrong
            }
            else
                return false;  //already in DB
        }
        //Get this item from the XML file and
        //add this item to the database passed in as db
        public bool XMLUpdate(XmlReader f, OdbcConnection db)
        {
            if (!this.parseXML(f))  //parse the item from "f"
                return false;  //Leave if the parse failed


            //Is it in database?  Check that it is NOT.
            if (!this.IsInDatabase(db))
            {
                //if not, update it
                if (this.UpdateRow(db))
                    return true;
                else
                    return false; //if something went wrong
            }
            else
                return false;  //already in DB
        }
        //Get this item from the XML file and
        //delete this item from the database passed in as db
        public bool XMLDelete(XmlReader f, OdbcConnection db)
        {
            if (!this.parseXML(f))  //parse the item from "f"
                this.Item_ID = int.Parse(f.GetAttribute("item_id")); //if the parse fails it will get the items id to delete

            if (!this.IsInDatabase(db))
            {
                if (this.DeleteRow(db))
                    return true;
                else
                    return false;
            }
            else
                return false;
        }

在接下来的几行中,看看你想做的事情,比如

Console.WriteLine("Item " + theItem.Item_ID + " was added successfully.");
事实上,您有一个名为
LClass5
的类,其中有一个名为该名称的成员,很可能

Item theItem = new Item();
应该是

Item theItem = new LClass5();

现在,这不会神奇地从XML文件中获取任何信息,但我发现在
LClass5
中有一个
parseXML
方法可以帮助您完成这一步骤。或者
XMLAdd
XMLUpdate
XMLDelete
方法也在
LClass5
中,尽管这些方法似乎违反了单一责任原则。

错误1找不到类型或命名空间名称“Item”(是否缺少using指令或程序集引用?)您没有向我们显示类型这是我的全部代码,我不太确定您的意思。您的程序中没有
定义,如果您不清楚,请尝试CTRL-F。
类项的代码在哪里?
Item theItem = new LClass5();