Question

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.

Was it helpful?

Solution

Try

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top