Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'

Tags:

c#

I have following exception in the foreach loop

Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'

How to solve the issue?

like image 689
Asim Sajjad Avatar asked Mar 17 '10 08:03

Asim Sajjad


2 Answers

A DataRowView is not a DataRow, and isn't convertible to a DataRow. However, you can access the corresponding DataRow using the Row property :

foreach(DataRowView drv in dataView)
{
    DataRow row = drv.Row;
    ...
}
like image 62
Thomas Levesque Avatar answered Oct 24 '22 05:10

Thomas Levesque


You can cast like:

datarow= DirectCast (System.Data.DataRowView, System.Data.DataRow).row 
like image 29
Siddhanath Lawand Avatar answered Oct 24 '22 05:10

Siddhanath Lawand