views:

279

answers:

2

I have a dataset containing a datatable, and I enumerate all rows in that datatable. When trying to format a column in that row, I run into an exception. (Part of) the code is:

For Each dr As DataRow In ds.Tables("records").Rows
    file = dr("timestamp").ToString("yyyyMMdd") & "~.wav"
Next

This results in the following error message:

Conversion from string yyyyMMdd to type Integer is not valid. (translated from a Dutch error message to the English equivalent)

dr("timestamp").GetType.FullName results in "System.DateTime", so I don't understand why I run into this exception, as for example Now.ToString("yyyyMMdd") results in "20091002", and "Now" is of the same type as dr("timestamp"), "System.DateTime" that is.

+3  A: 

Try

For Each dr As DataRow In ds.Tables("records").Rows
    file = CDate(dr("timestamp")).ToString("yyyyMMdd") & "~.wav"
Next
Justin Wignall
This did the trick. Thanks a lot for helping me out. Unfortunately I cannot mod your answer up, as I do not seem to have the required credits for that :(
iar
Well, he got a +1 from me ;) Also you can set his answer as "accepted" by clicking the green "v" (checkmark) below the up/downvote number.
sindre j
Although this checkmark is pretty big, I didn't notice it ;)Answer is now accepted though.
iar
A: 

Have you made sure that you are not declaring the variable 'file' as an integer?

Martin
file was declared as string, but thanks for helping me anyway.
iar