前幾日有學員反映按照《Scott Mitchell 的ASP.NET 2.0資料教程之二》中的例子仿寫,結果無法運行程式,報錯誤,找不到名為"NorithwindTableAdapters"的命名空間,導致程式無法運行。
出錯資訊為:“錯誤 1 找不到類型或命名空間名稱“NorithwindTableAdapters”(是否缺少 using 指令或程式集引用?) D:\Code\Northwind\Web\App_Code\BLL\Categories.cs 10 7 D:\...\Web\
”。
遇到這種問題可以通過GOOGLE搜尋,得到想要的答案,老外是這樣回答的(參見http://forums.asp.net/t/1010504.aspx):
I was able to fix this, though I still don't understand why it happens.
As Mr. Freeman (great job against the Xen, by the way) mentioned, the namespace is auto-generated by VS.Net. You can find out what namespace it created by opening the Class View and looking for the namespace objects (they look like braces: {}), in my case:
namespace Northwind
sTableAdapters;
Notice the bold "s"? Changing the code to this namespace worked. Why VS did this I have no idea, neither VS nor the tutorial gives any indication where this name comes from.
I typed the code in myself rather than downloading it; I find I don't learn anything by downloading and running samples.
意思就是說:請開啟你VS.NET 2005的“類別檢視”視窗,尋找你的命名空間究竟為什麼,注意這裡的命名空間應該是帶"S"的命名,然後在程式中引用即可。
另外,其中用到了設計模式的“單件”模式,不清楚的同學請Google相關資料。