Cannot convert type 'object[]' to 'System.Data.DataRow'

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

DataRow dr = (DataRow)ds.Tables[0].Rows[1].ItemArray;

Error 1 Cannot convert type 'object[]' to 'System.Data.DataRow' C:\Documents
and Settings\Fabio\Meus documentos\Visual Studio
2005\Projects\CodBarraPalm\CodBarraPalm\Default.aspx.cs 35 26 CodBarraPalm
?

why this error trying to get the contents of a row on a DataSet?
 
DataRow dr = (DataRow)ds.Tables[0].Rows[1].ItemArray;

Error 1 Cannot convert type 'object[]' to 'System.Data.DataRow' C:\Documents
and Settings\Fabio\Meus documentos\Visual Studio
2005\Projects\CodBarraPalm\CodBarraPalm\Default.aspx.cs 35 26 CodBarraPalm
?

why this error trying to get the contents of a row on a DataSet?

This error is because you are refering to the ItemArray. ItemArray
returns an array of objects that contains the values of each column in
the DataRow by ordinal. Simply remove the ".ItemArray" and that will
work.

DataRow dr = (DataRow)ds.Tables[0].Rows[1];

In the future, you might want to actually look at the error
description. It specifically says that it can't convert an array of
objects "object[]" to a DataRow.
Happy coding!
 
Back
Top