无法将类型'object'隐式转换为'System.Data.DataSet'.存在显式转换(您是否缺少演员表?) [英] Cannot implicitly convert type 'object' to 'System.Data.DataSet'. An explicit conversion exists (are you missing a cast?)

查看:75
本文介绍了无法将类型'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;


这篇关于无法将类型'object'隐式转换为'System.Data.DataSet'.存在显式转换(您是否缺少演员表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆