无法找到命名空间但已创建?

时间:2015-04-06 01:40:53

标签: c# namespaces syntax-error

我正在开发一个已经完成的程序。但唯一的问题是我无法通过这个错误。

  

错误1:类型或命名空间名称'项目'找不到(你错过了使用指令或汇编引用吗?)

有人可以向我解释为什么我的名字确实有参考时会收到此错误吗? (据我所知)。

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



namespace Lab_5
{
    class Program
    {
        static void Main(string[] args)
        {

            string conString = "Driver={MySQL ODBC 5.3 ANSI Driver};"
                + "Server=xxx;Port=xxx;"
                + "Database=xxx;"
                + "uid=xxx;pwd=xxx";
            OdbcConnection connection = new OdbcConnection(conString);
            connection.Open();




            string filepath = @"f:\sai430\output\";
            string filename = @"Update.xml";


            XmlReader theFile = XmlReader.Create(filepath + filename);




            while (theFile.Read())
            {
                    Item theItem = new Item();
                Item theItem = new Item();



                if (theFile.Name.Equals("ADD"))
                {
                    if (theFile.Name.Equals("ADD"))
                        Console.WriteLine("Item " + theItem.Item_ID + " was added successfully.");
                    else
                        Console.WriteLine("Problem upadating " + theItem.Item_ID + ".");

                }

                else if (theFile.Name.Equals("UPDATE"))
                {
                    if (theFile.Name.Equals("UPDATE"))
                        Console.WriteLine("Item " + theItem.Item_ID + " was updated successfully.");
                    else
                        Console.WriteLine("Problem upadating " + theItem.Item_ID + ".");
                }

                else if (theFile.Name.Equals("DELETE"))
                {
                    if (theFile.Name.Equals("DELETE"))
                        Console.WriteLine("Item " + theItem.Item_ID + " was deleted successfully.");
                    else
                        Console.WriteLine("Problem deleting " + theItem.Item_ID + ".");

            }



        }  

这就是我对Class.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;
        }

1 个答案:

答案 0 :(得分:0)

在接下来的几行中查看您尝试做的事情,例如

Console.WriteLine("Item " + theItem.Item_ID + " was added successfully.");

并且您有一个名为LClass5的类,其成员具有该名称,这似乎很可能就行了

Item theItem = new Item();

应该是

Item theItem = new LClass5();

现在,我们无法将您的XML theFile中的任何信息神奇地传输到theItem,但我发现您在parseXML中有一个LClass5方法,可能会帮助你完成这一步。或者也可能是XMLAdd中的XMLUpdateXMLDeleteLClass5方法,尽管这些方法似乎违反了单一责任原则。