无法将类型'object'隐式转换为'System.Data.DataSet'.存在显式转换(您是否缺少演员表?)
问题描述:
你好,
我在vb.net中有一个代码:
Hello,
i have a code in vb.net :
<pre lang="vb">Dim oDs As DataSet = GridView1.DataSource</pre><br />
当我运行此代码时,它没有显示错误.
当我转换为c-sharp时:
and when i run this code,it shows no error.
when i convert to c-sharp :
DataSet oDs = GridView1.DataSource;<br />
它显示错误:
无法将类型对象"隐式转换为"System.Data.DataSet".存在显式转换(您是否缺少演员表?)
谁能帮我这个忙,我为此已经挠了两天..我不明白强制转换的意思是什么,我们应该对代码做什么.
it shows error:
Cannot implicitly convert type ''object'' to ''System.Data.DataSet''. An explicit conversion exists (are you missing a cast?)
can anyone help me on this,i had been scratching my head for 2 days for this..i dont understand what is the cast means,what should we do with the code.
答
您好,
这适用于VB,因为在VB中存在隐式转换.
但是对于C#,则需要提供类型转换信息.
在C#中,没有隐式转换.
试试这个代码
Hi,
This is working with VB because in VB implicit conversion exists.
But in case of C#, you need to provide type cast information.
In C#, There is no implicit conversion.
Try this code
DataSet oDs = (DataSet)GridView1.DataSource;
可能会对您有帮助.
问候
AR
It might help you.
Regards
AR
尝试一下:
数据集ds = new Dataset();
//写查询..
gridview1.dataSource = ds;
Try this:
Dataset ds=new Dataset();
//Write your query..
gridview1.dataSource=ds;
尝试:DataSet oDs = (DataSet)GridView1.DataSource;
Try:DataSet oDs = (DataSet)GridView1.DataSource;