4 Replies - 369 Views - Last Post: 28 December 2012 - 11:30 AM Rate Topic: -----

#1 mouse88  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 192
  • Joined: 27-July 10

Typed Dataset Cast Issue With Row

Posted 28 December 2012 - 09:30 AM

If possible can anyone advise why I would get a cast issue on the following code:

Change_LogDataSet.tblChangesRow TableRow = ChangeDataModule.ChangesDataTable.NewtblChangesRow(); //Create new row.
TableRow = ChangeDataModule.ChangesDataTable.Rows[0];



It gives the following error:

Posted Image

If I do it in a for each loop it works fine:

foreach (Change_LogDataSet.tblChangesRow TableRow in ChangeDataModule.ChangesDataTable)



Is This A Good Question/Topic? 0
  • +

Replies To: Typed Dataset Cast Issue With Row

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 353
  • View blog
  • Posts: 1,513
  • Joined: 08-April 09

Re: Typed Dataset Cast Issue With Row

Posted 28 December 2012 - 10:40 AM

Maybe because they are different data types, C# is verytype safe language.

The error is pretty self explanatory, you have to have explicit cast.
Was This Post Helpful? 1
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Typed Dataset Cast Issue With Row

Posted 28 December 2012 - 10:42 AM

The foreach statement does a cast to the type, from the documentation: The type of the collection element must be convertible to the identifier type.

You just need to cast in the first example to make it work.
Was This Post Helpful? 1
  • +
  • -

#4 mouse88  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 192
  • Joined: 27-July 10

Re: Typed Dataset Cast Issue With Row

Posted 28 December 2012 - 11:15 AM

Please can you advise how one would cast to the type 'tblChangesRow'?
Was This Post Helpful? 0
  • +
  • -

#5 mouse88  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 192
  • Joined: 27-July 10

Re: Typed Dataset Cast Issue With Row

Posted 28 December 2012 - 11:30 AM

I managed to solve this. All I had to do was take out the .Rows[0] as below:

Change_LogDataSet.tblChangesRow TableRow = ChangeDataModule.ChangesDataTable.NewtblChangesRow(); //Create new row.
TableRow = ChangeDataModule.ChangesDataTable.Rows[0];
tbCreationDate.Text = TableRow.CreationDate.ToShortDateString();



To

Change_LogDataSet.tblChangesRow TableRow = ChangeDataModule.ChangesDataTable.NewtblChangesRow(); //Create new row.
TableRow = ChangeDataModule.ChangesDataTable[0];
tbCreationDate.Text = TableRow.CreationDate.ToShortDateString();


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1