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

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?
 
N

Norm

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top