-1
我正在研究一個基本完成的程序。但唯一的問題是我無法通過這個錯誤。找不到命名空間,但已創建?
錯誤1:類型或命名空間名稱「項目」找不到(是否缺少using指令或程序集引用?)
有人能向我解釋爲什麼我收到這個名稱確實有參考時出錯? (據我所知)。
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;
}
什麼錯誤? – SLaks 2015-04-06 01:41:58
錯誤1無法找到類型或命名空間名稱'Item'(您是否缺少使用指令或程序集引用?) – OldZero 2015-04-06 01:44:05
您沒有向我們顯示該類型 – SLaks 2015-04-06 01:45:33