VS2005,C# - 数据绑定组合框 - 默认情况下代码隐藏给我错误

时间:2009-05-21 14:49:26

标签: c# desktop-application

在代码的designer.cs部分,我只是简单地对组合框进行数据库驱动(它预览数据很好,这样才有效)但是当我尝试编译时,它会抛出2个独特的错误:

1)错误1“DesktopApplication.DesktopApplication”类型中不存在类型名称“mtdDesktopApplicationDataSet”

2)错误2“DesktopApplication.DesktopApplication”类型中不存在类型名称“mtdDesktopApplicationDataSetTableAdapters”

第一个错误出现在第一行,另一个错误显示在'mtdDesktopApplicationDataSetTableAdapters'所在的位置(4行)

所有相应的文件似乎都在那里,但它们只是没有连接好吗?

this.mtdDesktopApplicationDataSet = new DesktopApplication.mtdDesktopApplicationDataSet();
this.tblStudyBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.tblStudyTableAdapter = new DesktopApplication.mtdDesktopApplicationDataSetTableAdapters.tblStudyTableAdapter();
this.tblDeliveryGroupBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.tblDeliveryGroupTableAdapter = new DesktopApplication.mtdDesktopApplicationDataSetTableAdapters.tblDeliveryGroupTableAdapter();
this.tblDeliveryBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.tblDeliveryTableAdapter = new DesktopApplication.mtdDesktopApplicationDataSetTableAdapters.tblDeliveryTableAdapter();
this.tblDeliveryDataSetBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.tblDeliveryDataSetTableAdapter = new DesktopApplication.mtdDesktopApplicationDataSetTableAdapters.tblDeliveryDataSetTableAdapter();
 ((System.ComponentModel.ISupportInitialize)(this.mtdDesktopApplicationDataSet)).BeginInit();
 ((System.ComponentModel.ISupportInitialize)(this.tblStudyBindingSource)).BeginInit();
 ((System.ComponentModel.ISupportInitialize)(this.tblDeliveryGroupBindingSource)).BeginInit();
 ((System.ComponentModel.ISupportInitialize)(this.tblDeliveryBindingSource)).BeginInit();
 ((System.ComponentModel.ISupportInitialize)(this.tblDeliveryDataSetBindingSource)).BeginInit();

2 个答案:

答案 0 :(得分:2)

您是否在任何时候移动/重命名了文件/类,和/或更改了项目的默认命名空间?我已经看到所有这些都与上面的效果相似。

重新生成(生成)行:

this.mtdDesktopApplicationDataSet =
        new DesktopApplication.mtdDesktopApplicationDataSet();

可能值得避免让字段(this.mtdDesktopApplicationDataSet)与类型(DesktopApplication.mtdDesktopApplicationDataSet)命名相同 - 这只会导致潜在的错误。目前尚不清楚(无法重现)这是否是一个因素,但它无济于事......

要表示的字段mtdDesktopApplicationDataSet是什么?你可以重命名吗?

答案 1 :(得分:2)

我猜你正在遇到名称空间的一些问题。如果此代码隐藏文件驻留在DesktopApplication命名空间中,并且DesktopApplication命名空间中也有DesktopApplication类,您将体验上述内容。

(基本上它正在查看DesktopApplication.DesktopApplication,而应该查看DesktopApplication。)

尝试清理命名空间,以便上述情况不正确,或使用global关键字转义命名空间地狱:

this.mtdDesktopApplicationDataSet = new global::DesktopApplication.mtdDesktopApplicationDataSet();