conversion from string yyyyMMdd to type integer is

2019-05-21 06:35发布

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.

2条回答
狗以群分
2楼-- · 2019-05-21 06:57

Try

For Each dr As DataRow In ds.Tables("records").Rows
    file = CDate(dr("timestamp")).ToString("yyyyMMdd") & "~.wav"
Next
查看更多
看我几分像从前
3楼-- · 2019-05-21 06:59

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

查看更多
登录 后发表回答