当前位置:编程学习 > C#/ASP.NET >>

这句vb代码Dim dv As Data.DataView = Me.GridView1.DataSource 如何改写成c#

 Dim dv As Data.DataView = Me.GridView1.DataSource

上面代码vb运行正常好使,我想给改写成c#,我写的是
 DataTable dt = new DataTable(); 
  dt=this.GridView1.DataSource as DataTable ;

程序运行后报错如下:
未将对象引用设置到对象的实例。

请问该怎么改写,写写 --------------------编程问答-------------------- 上面是我想取datatable看看,下面是我取dataview的改写

Dim dv As Data.DataView = Me.GridView1.DataSource 

上面代码vb运行正常好使,我想给改写成c#,我写的是 
 DataView dv = new DataTable();  
  dv=this.GridView1.DataSource as DataView ; 

程序运行后报错如下: 
未将对象引用设置到对象的实例。 --------------------编程问答--------------------

DataTable dt;
DataSet ds;
ds=(DataSet)GridView1.DataSource;
dt=ds.Tables[0];

供你参考 --------------------编程问答-------------------- 学习了 --------------------编程问答--------------------
引用 2 楼 tonyepaper 的回复:
C# code

DataTable dt;
DataSet ds;
ds=(DataSet)GridView1.DataSource;
dt=ds.Tables[0];


供你参考

支持 --------------------编程问答--------------------
引用楼主 rainbow_9982 的回复:
Dim dv As Data.DataView = Me.GridView1.DataSource

上面代码vb运行正常好使,我想给改写成c#,我写的是
DataTable dt = new DataTable();
  dt=this.GridView1.DataSource as DataTable ;

程序运行后报错如下:
未将对象引用设置到对象的实例。

请问该怎么改……

不懂你到放在GradiView1.DataSource里面的到底是什么。
放什么进去拿出来什么就不会有这样的问题了。

比如:
GradiView1.DataSource = new DataTable();
DataTable dt = GradiView1.DataSource as DataTable;
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,