sqlitedatatabledatarowdelphi-prismoxygene

Type mismatch, cannot assign System.Data.DataRowCollection to array of System.Data.DataRow


I want to be able to traverse through a list of DataRow using For each loop as follows.

  ArrayOfRows: Array of DataRow;

  ArrayOfRows := dbtable.Rows;

  for each therow in ArrayofRows do
  begin
    ITagList.Add(therow['TAGNAME'].ToString);
  end;

But I keep running to the error,

"Type mismatch, cannot assign System.Data.DataRowCollection to array of System.Data.DataRow."

How do you traverse through a list of rows in a datatable?

Thanks in advance,


Solution

  • Use System.Data.DataRowCollection.CopyTo(), which is designed to do exactly this.

    public override void CopyTo(
    Array ar,
    int index
    )
    

    The parameters are the array you want to copy into, and the zero-based index where the copy should start.