且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将类型'System.Data.DataRelation'隐式转换为'DataRelation'

更新时间:2023-02-24 19:27:25

System.Data命名空间已经包含一个名为DataRelation的类,并且该类是从DataSet返回的.添加方法调用.
您尝试将其存储在其中的变量被声明为DataRelation-这是您的方法所在的类名称.在这两个不相关的类型之间未定义任何转换.

更改类的名称(但不要更改relation的定义)或完全限定该定义:
The System.Data namespace already contains a class called DataRelation, and this is returned from a DataSet.Relations.Add method call.
The variable you have tried to store it in is declared as a DataRelation - which is the class name your method sits in. There is no conversion defined between the two unrelated types.

Either change the name of your class (but don''t change the definition of relation) or fully qualify the definition:
System.Data.DataRelation relation;

就我个人而言,如果我要使用System.Data,我不会将我的类称为冲突名称,只是为了避免混淆!

Personally, if I was going to use System.Data, I would not call my class a conflicting name, just to avoid confusion!