简体   繁体   中英

VS2005, C# - Databound combo boxes - code behind is giving me errors by default

In the designer.cs portion of the code, I simply made the combo boxes database driven (it previewed the data fine, so that works) but when I try to compile, it throws me a 2 unique errors:

1) Error 1 The type name 'mtdDesktopApplicationDataSet' does not exist in the type 'DesktopApplication.DesktopApplication'

2) Error 2 The type name 'mtdDesktopApplicationDataSetTableAdapters' does not exist in the type 'DesktopApplication.DesktopApplication'

The first error is on the first line, the other error shows up wherever 'mtdDesktopApplicationDataSetTableAdapters' is (4 lines)

All the appropriate files appear to be there, but they just aren't hooking up right?

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();

Have you moved/renamed the files/classes at any point, and/or changed the project's default namespace? I've seen all of these have similar effects to the above.

Re the (generated) line:

this.mtdDesktopApplicationDataSet =
        new DesktopApplication.mtdDesktopApplicationDataSet();

It is probably worth avoiding having fields ( this.mtdDesktopApplicationDataSet ) named the same as types ( DesktopApplication.mtdDesktopApplicationDataSet ) - that can only lead to potential for bugs. It isn't clear (without being able to reproduce it) whether that is a factor here, but it can't help any...

What is the field mtdDesktopApplicationDataSet meant to represent? Can you rename it?

I'm guessing you're experiencing some issues with namespaces. If this code-behind file resides in the DesktopApplication namespace and you also have a DesktopApplication class in the DesktopApplication namespace, you will experience the above.

(Basically it's looking at DesktopApplication.DesktopApplication when it should be looking at DesktopApplication instead.)

Try cleaning up your namespaces so the above is not true, or escape the namespace hell with the global keyword:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM